mirror of
https://github.com/DataTables/DataTables.git
synced 2025-04-12 04:02:29 +02:00
- Ability to filter the table through the new API. - This effectively replaces the fnFilter method of the old API. - Note that one capability which has been removed from the old API is the ability to not show the new filter on the filtering input elements. I can't see any use for that feature to be honest, so it has been dropped. The filtering inputs always show the global filter state now. - Additionally, note that we've been forced to call this `search` here rather than `filter` since there is a `filter` method for the API collection instance. This might be revisted before release.
212 lines
5.2 KiB
JavaScript
212 lines
5.2 KiB
JavaScript
|
|
/**
|
|
* Return the settings object for a particular table
|
|
* @param {node} nTable table we are using as a dataTable
|
|
* @returns {object} Settings object - or null if not found
|
|
* @memberof DataTable#oApi
|
|
*/
|
|
function _fnSettingsFromNode ( nTable )
|
|
{
|
|
for ( var i=0 ; i<DataTable.settings.length ; i++ )
|
|
{
|
|
if ( DataTable.settings[i].nTable === nTable )
|
|
{
|
|
return DataTable.settings[i];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
/**
|
|
* Log an error message
|
|
* @param {object} oSettings dataTables settings object
|
|
* @param {int} iLevel log error messages, or display them to the user
|
|
* @param {string} sMesg error message
|
|
* @memberof DataTable#oApi
|
|
*/
|
|
function _fnLog( oSettings, iLevel, sMesg )
|
|
{
|
|
var sAlert = (oSettings===null) ?
|
|
"DataTables warning: "+sMesg :
|
|
"DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
|
|
|
|
if ( iLevel === 0 )
|
|
{
|
|
if ( DataTable.ext.sErrMode == 'alert' )
|
|
{
|
|
alert( sAlert );
|
|
}
|
|
else
|
|
{
|
|
throw new Error(sAlert);
|
|
}
|
|
return;
|
|
}
|
|
else if ( window.console && console.log )
|
|
{
|
|
console.log( sAlert );
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* See if a property is defined on one object, if so assign it to the other object
|
|
* @param {object} oRet target object
|
|
* @param {object} oSrc source object
|
|
* @param {string} sName property
|
|
* @param {string} [sMappedName] name to map too - optional, sName used if not given
|
|
* @memberof DataTable#oApi
|
|
*/
|
|
function _fnMap( oRet, oSrc, sName, sMappedName )
|
|
{
|
|
if ( sMappedName === undefined )
|
|
{
|
|
sMappedName = sName;
|
|
}
|
|
if ( oSrc[sName] !== undefined )
|
|
{
|
|
oRet[sMappedName] = oSrc[sName];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Extend objects - very similar to jQuery.extend, but deep copy objects, and shallow
|
|
* copy arrays. The reason we need to do this, is that we don't want to deep copy array
|
|
* init values (such as aaSorting) since the dev wouldn't be able to override them, but
|
|
* we do want to deep copy objects.
|
|
* @param {object} oOut Object to extend
|
|
* @param {object} oExtender Object from which the properties will be applied to oOut
|
|
* @returns {object} oOut Reference, just for convenience - oOut === the return.
|
|
* @memberof DataTable#oApi
|
|
* @todo This doesn't take account of arrays inside the deep copied objects.
|
|
*/
|
|
function _fnExtend( oOut, oExtender )
|
|
{
|
|
var val;
|
|
|
|
for ( var prop in oExtender )
|
|
{
|
|
if ( oExtender.hasOwnProperty(prop) )
|
|
{
|
|
val = oExtender[prop];
|
|
|
|
if ( $.isPlainObject( val ) )
|
|
{
|
|
if ( ! oOut[prop] )
|
|
{
|
|
oOut[prop] = {};
|
|
}
|
|
$.extend( true, oOut[prop], val );
|
|
}
|
|
else
|
|
{
|
|
oOut[prop] = val;
|
|
}
|
|
}
|
|
}
|
|
|
|
return oOut;
|
|
}
|
|
|
|
|
|
/**
|
|
* Bind an event handers to allow a click or return key to activate the callback.
|
|
* This is good for accessibility since a return on the keyboard will have the
|
|
* same effect as a click, if the element has focus.
|
|
* @param {element} n Element to bind the action to
|
|
* @param {object} oData Data object to pass to the triggered function
|
|
* @param {function} fn Callback function for when the event is triggered
|
|
* @memberof DataTable#oApi
|
|
*/
|
|
function _fnBindAction( n, oData, fn )
|
|
{
|
|
$(n)
|
|
.bind( 'click.DT', oData, function (e) {
|
|
n.blur(); // Remove focus outline for mouse users
|
|
fn(e);
|
|
} )
|
|
.bind( 'keypress.DT', oData, function (e){
|
|
if ( e.which === 13 ) {
|
|
fn(e);
|
|
} } )
|
|
.bind( 'selectstart.DT', function () {
|
|
/* Take the brutal approach to cancelling text selection */
|
|
return false;
|
|
} );
|
|
}
|
|
|
|
|
|
/**
|
|
* Register a callback function. Easily allows a callback function to be added to
|
|
* an array store of callback functions that can then all be called together.
|
|
* @param {object} oSettings dataTables settings object
|
|
* @param {string} sStore Name of the array storage for the callbacks in oSettings
|
|
* @param {function} fn Function to be called back
|
|
* @param {string} sName Identifying name for the callback (i.e. a label)
|
|
* @memberof DataTable#oApi
|
|
*/
|
|
function _fnCallbackReg( oSettings, sStore, fn, sName )
|
|
{
|
|
if ( fn )
|
|
{
|
|
oSettings[sStore].push( {
|
|
"fn": fn,
|
|
"sName": sName
|
|
} );
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Fire callback functions and trigger events. Note that the loop over the callback
|
|
* array store is done backwards! Further note that you do not want to fire off triggers
|
|
* in time sensitive applications (for example cell creation) as its slow.
|
|
* @param {object} oSettings dataTables settings object
|
|
* @param {string} sStore Name of the array storage for the callbacks in oSettings
|
|
* @param {string} sTrigger Name of the jQuery custom event to trigger. If null no trigger
|
|
* is fired
|
|
* @param {array} aArgs Array of arguments to pass to the callback function / trigger
|
|
* @memberof DataTable#oApi
|
|
*/
|
|
function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
|
|
{
|
|
var aoStore = oSettings[sStore];
|
|
var aRet =[];
|
|
|
|
for ( var i=aoStore.length-1 ; i>=0 ; i-- )
|
|
{
|
|
aRet.push( aoStore[i].fn.apply( oSettings.oInstance, aArgs ) );
|
|
}
|
|
|
|
if ( sTrigger !== null )
|
|
{
|
|
$(oSettings.oInstance).trigger(sTrigger, aArgs);
|
|
}
|
|
|
|
return aRet;
|
|
}
|
|
|
|
|
|
function _fnLengthOverflow ( settings )
|
|
{
|
|
var
|
|
start = settings._iDisplayStart,
|
|
end = settings.fnDisplayEnd(),
|
|
len = settings._iDisplayLength;
|
|
|
|
/* If we have space to show extra rows (backing up from the end point - then do so */
|
|
if ( end === settings.fnRecordsDisplay() )
|
|
{
|
|
start = end - len;
|
|
}
|
|
|
|
if ( len === -1 || start < 0 )
|
|
{
|
|
start = 0;
|
|
}
|
|
|
|
settings._iDisplayStart = start;
|
|
} |