Filtering Bug

Filtering Bug

kobyckobyc Posts: 1Questions: 0Answers: 0
edited January 2012 in Bug reports
1 - Attached code sample (filter.html)
Symptom: filter shows column containing 'inactive' when the filter is set to 'active'
The code calls fnFilter with bRegex and bSmart both set to false (line 98)

2 - Using jquery.dataTables.js version 1.8.2
fnFilter starts line 1538
calls _fnFilterComplete line 1586 using oPreviousSearch as argument (defined line 1057)
_fnFilterComplete starts line 4332
creates filter (call to _fnFilter line 4335 with oPreviousSearch as arguments)
this seems to ignore the values of bRegex and bSmart passed when calling fnFilter

3- Even if the value for bRegex was correctly set to false,
this eventually calls _fnFilterCreateSearch (line 4577)
if bSmart is false and bRegex is false, the function returns
return new RegExp( sSearch, "i" );
e.g. a regex for "/active/i" which will match both 'active' (as expected) and 'inactive' (unexpected)
Fixed it by changing the return value when bRegex is false
if (bRegex) {
sSearch = _fnEscapeRegex( sSearch );
return new RegExp( sSearch, "i" );
}
return new RegExp ( "^"+sSearch+"$", "i")

filter.html:
[code]











title
value




active
one


active
two


inactive
three




titlefilter
valuefilter





(function($) {
$.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
// check that we have a column id
if ( typeof iColumn == "undefined" ) return new Array();

// by default we only wany unique data
if ( typeof bUnique == "undefined" ) bUnique = true;

// by default we do want to only look at filtered data
if ( typeof bFiltered == "undefined" ) bFiltered = true;

// by default we do not wany to include empty values
if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;

// list of rows which we're going to loop through
var aiRows;

// use only filtered rows
if (bFiltered == true) aiRows = oSettings.aiDisplay;
// use all rows
else aiRows = oSettings.aiDisplayMaster; // all row numbers

// set up data array
var asResultData = new Array();

for (var i=0,c=aiRows.length; i -1) continue;

// else push the value onto the result data array
else asResultData.push(sValue);
}

return asResultData;
}}(jQuery));
function fnCreateSelect( aData )
{
var r='', i, iLen=aData.length;
for ( i=0 ; i

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    [quote]
    1 - Attached code sample (filter.html)
    Symptom: filter shows column containing 'inactive' when the filter is set to 'active'
    The code calls fnFilter with bRegex and bSmart both set to false (line 98)
    [/quote]

    Sounds like it is working as expected to me :-). The string "active" is present in both "active" and "inactive" - hence both match. If you want absolute string matching then use a little bit of regex "^active$" will match only columns with active with nothing else in them.

    Allan
This discussion has been closed.