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.rows.js');
require('api.columns.js');
require('api.search.js');
require('api.static.js');
/**

View File

@ -135,12 +135,14 @@ _api.register( 'columns().visible()', function ( vis ) {
// } );
_api.register( 'columns.adjust()', function () {
this.iterator( 'table', function ( settings ) {
return this.iterator( 'table', function ( settings ) {
_fnAdjustColumnSizing( settings );
} );
} );
// Convert from one column index type, to another type
_api.register( 'column.index()', function ( type, idx ) {
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++ ) {
if ( type === 'table' ) {
ret = fn( context[i] );
ret = fn( context[i], i );
if ( ret !== undefined ) {
a.push( ret );
@ -344,7 +344,7 @@ _Api.prototype = /** @lends DataTables.Api */{
}
else if ( type === 'columns' || type === 'rows' ) {
// 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 ) {
a.push( ret );

View File

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

View File

@ -100,7 +100,7 @@ function _fnFilterComplete ( oSettings, oInput, iForce )
fnSaveFilter( oInput );
/* 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,
aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );

View File

@ -1,29 +1,10 @@
function _fnLengthChange ( settings, val )
{
var
start = settings._iDisplayStart,
records = settings.fnRecordsDisplay(),
end,
len = parseInt( val, 10 );
/* Redraw the table */
var len = parseInt( val, 10 );
settings._iDisplayLength = len;
end = settings.fnDisplayEnd();
/* 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;
_fnLengthOverflow( settings );
// Fire length change event
$(settings.oInstance).trigger( 'length', [settings, len] );

View File

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