/**
* Perform a jQuery selector action on the table's TR elements (from the tbody) and
* return the resulting expression
* @param {string} sSelector jQuery selector
* @returns {object} jQuery object
*/
this.$ = function ( sSelector )
{
// xxx - filtering, sorting, column visibility options
var oSettings = _fnSettingsFromNode(this[_oExt.iApiIndex]);
return $(this.oApi._fnGetTrNodes(oSettings)).filter(sSelector);
};
/**
* Add a single new row or multiple rows of data to the table. Please note
* that this is suitable for client-side processing only - if you are using
* server-side processing (i.e. "bServerSide": true), then to add data, you
* must add it to the data source, i.e. the server-side, through an Ajax call.
* @param {array|object} mData The data to be added to the table. This can be:
*
* - 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 mDataProp
* - array of objects - multiple data objects when using mDataProp
*
* @param {bool} [bRedraw=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.
*
* @example
* // Global var for counter
* var giCount = 2;
*
* $(document).ready(function() {
* $('#example').dataTable();
* } );
*
* function fnClickAddRow() {
* $('#example').dataTable().fnAddData( [
* giCount+".1",
* giCount+".2",
* giCount+".3",
* giCount+".4" ]
* );
*
* giCount++;
* }
*/
this.fnAddData = function( mData, bRedraw )
{
if ( mData.length === 0 )
{
return [];
}
var aiReturn = [];
var iTest;
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
/* Check if we want to add multiple rows or not */
if ( typeof mData[0] == "object" )
{
for ( var i=0 ; i= oSettings.aiDisplay.length )
{
oSettings._iDisplayStart -= oSettings._iDisplayLength;
if ( oSettings._iDisplayStart < 0 )
{
oSettings._iDisplayStart = 0;
}
}
if ( typeof bRedraw == 'undefined' || bRedraw )
{
_fnCalculateEnd( oSettings );
_fnDraw( oSettings );
}
return oData;
};
/**
* 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.
*
* @example
* $(document).ready(function() {
* // This example is fairly pointless in reality, but shows how fnDestroy can be used
* var oTable = $('#example').dataTable();
* oTable.fnDestroy();
* } );
*/
this.fnDestroy = function ( )
{
var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
var nOrig = oSettings.nTableWrapper.parentNode;
var nBody = oSettings.nTBody;
var i, iLen;
/* Flag to note that the table is currently being destroyed - no action should be taken */
oSettings.bDestroying = true;
/* Restore hidden columns */
for ( i=0, iLen=oSettings.aoDestroyCallback.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(' ') );
if ( !oSettings.bJUI )
{
$('th', oSettings.nTHead).removeClass( [ _oExt.oStdClasses.sSortable,
_oExt.oStdClasses.sSortableAsc,
_oExt.oStdClasses.sSortableDesc,
_oExt.oStdClasses.sSortableNone ].join(' ')
);
}
else
{
$('th, td', oSettings.nTHead).removeClass( [ _oExt.oStdClasses.sSortable,
_oExt.oJUIClasses.sSortableAsc,
_oExt.oJUIClasses.sSortableDesc,
_oExt.oJUIClasses.sSortableNone ].join(' ')
);
$('th span.'+_oExt.oJUIClasses.sSortIcon
+ ', td span.'+_oExt.oJUIClasses.sSortIcon, oSettings.nTHead).remove();
$('th, td', oSettings.nTHead).each( function () {
var jqWrapper = $('div.'+_oExt.oJUIClasses.sSortJUIWrapper, this);
var kids = jqWrapper.contents();
$(this).append( kids );
jqWrapper.remove();
} );
}
/* Add the TR elements back into the table in their original order */
if ( oSettings.nTableReinsertBefore )
{
nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore );
}
else
{
nOrig.appendChild( oSettings.nTable );
}
for ( i=0, iLen=oSettings.aoData.length ; i= _fnVisbleColumns( oSettings ));
/* Which coloumn should we be inserting before? */
if ( !bAppend )
{
for ( i=iCol ; i