From f9179058dfda47c911fbf5f872e4b40e71829b7e Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Sat, 25 May 2013 08:17:13 +0100 Subject: [PATCH] Update: Deprecate old API. update `api()` method. - With the new API that is being introduced in v1.10, the old API (fnUpdate, fnAddData etc) is being deprecated and retired. It is now a shim layer calling through the new API, rather than duplicating the logic of the calls, but is still provided for backwards compatiblity. - It is _strongly_ recommended that you start to use the new API from this point in - very certainly for new projects. - The api() method, is not deprecated, it is new in 1.10 and provides a way to get access to a DataTables API instance from the jQuery host object, if the table is initlaised with `dataTable()` (rather than `DataTable()` which does give you the API instance. It has a single option which is used by the old API's shim layer to allow it to use the iApiIndex option to get the context to be used. --- media/src/api/api.methods.js | 832 ++++++----------------------------- 1 file changed, 145 insertions(+), 687 deletions(-) diff --git a/media/src/api/api.methods.js b/media/src/api/api.methods.js index 1609edb5..e1bb3029 100644 --- a/media/src/api/api.methods.js +++ b/media/src/api/api.methods.js @@ -35,94 +35,7 @@ */ this.$ = function ( sSelector, oOpts ) { - var i, iLen, a = [], tr; - var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ); - var aoData = oSettings.aoData; - var aiDisplay = oSettings.aiDisplay; - var aiDisplayMaster = oSettings.aiDisplayMaster; - - if ( !oOpts ) - { - oOpts = {}; - } - - oOpts = $.extend( {}, { - "filter": "none", // applied - "order": "current", // "original" - "page": "all" // current - }, oOpts ); - - // Current page implies that order=current and fitler=applied, since it is fairly - // senseless otherwise - if ( oOpts.page == 'current' ) - { - for ( i=oSettings._iDisplayStart, iLen=oSettings.fnDisplayEnd() ; i *
  • 1D array of data - add a single row with the data provided
  • *
  • 2D array of arrays - add multiple rows in a single call
  • *
  • object - data object when using mData
  • *
  • array of objects - multiple data objects when using mData
  • * - * @param {bool} [bRedraw=true] redraw the table or not + * @param {bool} [redraw=true] redraw the table or not * @returns {array} An array of integers, representing the list of indexes in * aoData ({@link DataTable.models.oSettings}) that have been added to * the table. * @dtopt API + * @deprecated Since v1.10 * * @example * // Global var for counter @@ -235,49 +150,20 @@ this.api = function () * giCount++; * } */ -this.fnAddData = function( mData, bRedraw ) +this.fnAddData = function( data, redraw ) { - if ( mData.length === 0 ) - { - return []; - } - - var aiReturn = []; - var iTest; - - /* Find settings from table node */ - var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ); - + var api = this.api( true ); + /* Check if we want to add multiple rows or not */ - if ( typeof mData[0] === "object" && mData[0] !== null ) - { - for ( var i=0 ; i= oSettings.fnRecordsDisplay() ) - { - oSettings._iDisplayStart -= oSettings._iDisplayLength; - if ( oSettings._iDisplayStart < 0 ) - { - oSettings._iDisplayStart = 0; - } - } - - if ( bRedraw === undefined || bRedraw ) - { - _fnDraw( oSettings ); - } - - return oData; + + return data; }; /** * Restore the table to it's original state in the DOM by removing all of DataTables * enhancements, alterations to the DOM structure of the table and event listeners. - * @param {boolean} [bRemove=false] Completely remove the table from the DOM + * @param {boolean} [remove=false] Completely remove the table from the DOM * @dtopt API + * @deprecated Since v1.10 * * @example * $(document).ready(function() { @@ -474,138 +310,17 @@ this.fnDeleteRow = function( mTarget, fnCallBack, bRedraw ) * oTable.fnDestroy(); * } ); */ -this.fnDestroy = function ( bRemove ) +this.fnDestroy = function ( remove ) { - var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] ); - var nOrig = oSettings.nTableWrapper.parentNode; - var nBody = oSettings.nTBody; - var i, iLen; - - bRemove = (bRemove===undefined) ? false : bRemove; - - /* Flag to note that the table is currently being destroyed - no action should be taken */ - oSettings.bDestroying = true; - - /* Fire off the destroy callbacks for plug-ins etc */ - _fnCallbackFire( oSettings, "aoDestroyCallback", "destroy", [oSettings] ); - - /* If the table is not being removed, restore the hidden columns */ - if ( !bRemove ) - { - for ( i=0, iLen=oSettings.aoColumns.length ; itr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove(); - - /* When scrolling we had to break the table up - restore it */ - if ( oSettings.nTable != oSettings.nTHead.parentNode ) - { - $(oSettings.nTable).children('thead').remove(); - oSettings.nTable.appendChild( oSettings.nTHead ); - } - - if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode ) - { - $(oSettings.nTable).children('tfoot').remove(); - oSettings.nTable.appendChild( oSettings.nTFoot ); - } - - /* Remove the DataTables generated nodes, events and classes */ - oSettings.nTable.parentNode.removeChild( oSettings.nTable ); - $(oSettings.nTableWrapper).remove(); - - oSettings.aaSorting = []; - oSettings.aaSortingFixed = []; - _fnSortingClasses( oSettings ); - - $(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripeClasses.join(' ') ); - - $('th, td', oSettings.nTHead).removeClass( [ - oSettings.oClasses.sSortable, - oSettings.oClasses.sSortableAsc, - oSettings.oClasses.sSortableDesc, - oSettings.oClasses.sSortableNone ].join(' ') - ); - if ( oSettings.bJUI ) - { - $('th span.'+oSettings.oClasses.sSortIcon - + ', td span.'+oSettings.oClasses.sSortIcon, oSettings.nTHead).remove(); - - $('th, td', oSettings.nTHead).each( function () { - var jqWrapper = $('div.'+oSettings.oClasses.sSortJUIWrapper, this); - var kids = jqWrapper.contents(); - $(this).append( kids ); - jqWrapper.remove(); - } ); - } - - /* Add the TR elements back into the table in their original order */ - if ( !bRemove && oSettings.nTableReinsertBefore ) - { - nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore ); - } - else if ( !bRemove ) - { - nOrig.appendChild( oSettings.nTable ); - } - - for ( i=0, iLen=oSettings.aoData.length ; i