1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-02-07 05:54:15 +01:00

New: search() and columns().search() API methods

- 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.
This commit is contained in:
Allan Jardine 2013-04-29 07:51:41 +01:00
parent 2b0a321dd2
commit d7058eb45d
7 changed files with 39 additions and 34 deletions

View File

@ -117,6 +117,7 @@
require('api._selectors.js'); require('api._selectors.js');
require('api.rows.js'); require('api.rows.js');
require('api.columns.js'); require('api.columns.js');
require('api.search.js');
require('api.static.js'); require('api.static.js');
/** /**

View File

@ -135,12 +135,14 @@ _api.register( 'columns().visible()', function ( vis ) {
// } ); // } );
_api.register( 'columns.adjust()', function () { _api.register( 'columns.adjust()', function () {
this.iterator( 'table', function ( settings ) { return this.iterator( 'table', function ( settings ) {
_fnAdjustColumnSizing( settings ); _fnAdjustColumnSizing( settings );
} ); } );
} ); } );
// Convert from one column index type, to another type // Convert from one column index type, to another type
_api.register( 'column.index()', function ( type, idx ) { _api.register( 'column.index()', function ( type, idx ) {
if ( this.context.length !== 0 ) { if ( this.context.length !== 0 ) {

View File

@ -336,7 +336,7 @@ _Api.prototype = /** @lends DataTables.Api */{
for ( i=0, ien=context.length ; i<ien ; i++ ) { for ( i=0, ien=context.length ; i<ien ; i++ ) {
if ( type === 'table' ) { if ( type === 'table' ) {
ret = fn( context[i] ); ret = fn( context[i], i );
if ( ret !== undefined ) { if ( ret !== undefined ) {
a.push( ret ); a.push( ret );
@ -344,7 +344,7 @@ _Api.prototype = /** @lends DataTables.Api */{
} }
else if ( type === 'columns' || type === 'rows' ) { else if ( type === 'columns' || type === 'rows' ) {
// this has same length as context - one entry for each table // this has same length as context - one entry for each table
ret = fn( context[i], this[i] ); ret = fn( context[i], this[i], i );
if ( ret !== undefined ) { if ( ret !== undefined ) {
a.push( ret ); a.push( ret );

View File

@ -495,7 +495,7 @@ function _fnClearTable( oSettings )
* @param {int} iTarget value to find * @param {int} iTarget value to find
* @memberof DataTable#oApi * @memberof DataTable#oApi
*/ */
function _fnDeleteIndex( a, iTarget ) function _fnDeleteIndex( a, iTarget, splice )
{ {
var iTargetIndex = -1; var iTargetIndex = -1;
@ -511,7 +511,7 @@ function _fnDeleteIndex( a, iTarget )
} }
} }
if ( iTargetIndex != -1 ) if ( iTargetIndex != -1 && splice === undefined )
{ {
a.splice( iTargetIndex, 1 ); a.splice( iTargetIndex, 1 );
} }

View File

@ -100,7 +100,7 @@ function _fnFilterComplete ( oSettings, oInput, iForce )
fnSaveFilter( oInput ); fnSaveFilter( oInput );
/* Now do the individual column filter */ /* Now do the individual column filter */
for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ ) for ( var i=0 ; i<aoPrevSearch.length ; i++ )
{ {
_fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex, _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, aoPrevSearch[i].bRegex,
aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive ); aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );

View File

@ -1,29 +1,10 @@
function _fnLengthChange ( settings, val ) function _fnLengthChange ( settings, val )
{ {
var var len = parseInt( val, 10 );
start = settings._iDisplayStart,
records = settings.fnRecordsDisplay(),
end,
len = parseInt( val, 10 );
/* Redraw the table */
settings._iDisplayLength = len; settings._iDisplayLength = len;
end = settings.fnDisplayEnd(); _fnLengthOverflow( settings );
/* If we have space to show extra rows (backing up from the end point - then do so */
if ( end === records )
{
start = end - len;
}
if ( len === -1 || start < 0 )
{
start = 0;
}
settings._iDisplayStart = start;
// Fire length change event // Fire length change event
$(settings.oInstance).trigger( 'length', [settings, len] ); $(settings.oInstance).trigger( 'length', [settings, len] );

View File

@ -189,3 +189,24 @@ function _fnCallbackFire( oSettings, sStore, sTrigger, aArgs )
return aRet; 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;
}