1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-11-29 11:24:10 +01:00

Internal: Update the the filtering input control to update itself on filter

- Previously it was the domain of the filtering caller to update the
  global filtering input element (fnFilter or the keypress handler
  specifically), but in keeping with the drive towards modularity, it
  should be the control itself that updates when needed.

- This is done by listening for the `filter` event from the table and
  updating the display as needed. It is a touch less efficent since the
  same value might be written as what is already there, but it reduces
  code size and complexity.
This commit is contained in:
Allan Jardine 2013-04-29 07:58:53 +01:00
parent d7058eb45d
commit 955eb2cd99
2 changed files with 57 additions and 8 deletions

View File

@ -0,0 +1,43 @@
(/** @lends <global> */function() {
var _api = DataTable.Api;
_api.register( 'search()', function ( input, caseInsen, regex, smart ) {
return this.iterator( 'table', function ( settings ) {
if ( ! settings.oFeatures.bFilter ) {
return;
}
_fnFilterComplete( settings, {
"sSearch": input+"",
"bRegex": regex === null ? false : regex,
"bSmart": smart === null ? true : smart,
"bCaseInsensitive": caseInsen === null ? true : caseInsen
}, 1 );
} );
} );
_api.register( 'columns().search()', function ( input, caseInsen, regex, smart ) {
return this.iterator( 'column', function ( settings, column ) {
if ( ! settings.oFeatures.bFilter ) {
return;
}
$.extend( settings.aoPreSearchCols[ column ], {
"sSearch": input+"",
"bRegex": regex === null ? false : regex,
"bSmart": smart === null ? true : smart,
"bCaseInsensitive": caseInsen === null ? true : caseInsen
} );
_fnFilterComplete( settings, settings.oPreviousSearch, 1 );
} );
} );
}());

View File

@ -34,14 +34,6 @@ function _fnFeatureHtmlFilter ( oSettings )
var n = oSettings.aanFeatures.f;
var val = this.value==="" ? "" : this.value; // mental IE8 fix :-(
for ( var i=0, iLen=n.length ; i<iLen ; i++ )
{
if ( n[i] != $(this).parents('div.dataTables_filter')[0] )
{
$(n[i]._DT_Input).val( val );
}
}
/* Now do the filter */
if ( val != oPreviousSearch.sSearch )
{
@ -69,6 +61,20 @@ function _fnFeatureHtmlFilter ( oSettings )
}
);
// Update the input elements whenever the table is filtered
$(oSettings.nTable).on( 'filter.DT', function () {
try {
// IE9 throws an 'unknown error' if document.activeElement is used
// inside an iframe or frame...
if ( this._DT_Input !== document.activeElement ) {
jqFilter.val( oPreviousSearch.sSearch );
}
}
catch ( e ) {
jqFilter.val( oPreviousSearch.sSearch );
}
} );
return nFilter;
}