Individual Column Filter values not being reset
Individual Column Filter values not being reset
JustSimplyQ
Posts: 4Questions: 0Answers: 0
I have implemented individual column filters similar to what is seen in the following example:
http://datatables.net/examples/api/multi_filter.html
I took it a step further and implemented a 'clear all' feature that goes through and clears any filters that have been applied to the columns and resets the column's filter value to the value of that column's title.
The code for that is as follows:
[code]
$.fn.dataTableExt.oApi.fnFilterClear = function ( oSettings )
{
/* Remove global filter */
oSettings.oPreviousSearch.sSearch = "";
/* Remove the text of the global filter in the input boxes */
if ( typeof oSettings.aanFeatures.f != 'undefined' )
{
var n = oSettings.aanFeatures.f;
for ( var i=0, iLen=n.length ; i 7){j = i - 3;}
alert("oSettings.aoPreSearchCols[i].sSearch.length for i = " + i + " is " + oSettings.aoPreSearchCols[i].sSearch.length);
alert("cleaning up for j = " + j);
oSettings.aoPreSearchCols[i].sSearch = "";
$("thead input")[j].value = $("thead input")[j].title;
$("thead input")[j].className = "search_init";
alert("oSettings.aoPreSearchCols[i].sSearch is '" + oSettings.aoPreSearchCols[i].sSearch + "'");
alert("$(thead input)[j].value is " + $("thead input")[j].value);
}
}
/* Redraw */
oSettings.oApi._fnReDraw( oSettings );
alert("oSettings.aoPreSearchCols[3].sSearch is '" + oSettings.aoPreSearchCols[3].sSearch + "'");
};
[/code]
The problem is that it's clearing the search string that was in the value and setting the value parameter to the value of the title parameter -- just as expected -- however, when the table is redrawn, the old search string is still displayed in the input box. The value for that input box has been reset though because if I choose 'clear all' again, the sSearch.length for that column is zero.
I've found that if I hit 'clear all' and the table is redrawn and it still shows the previous search value, if I then use the browser's refresh option the input value is corrected.
Here's an example:
I have column 3 that is my customer's names. The input value is 'Customer' which is displayed in the input box and the title is also 'Customer'.
When I search for 'myFavoriteCustomer', the input value is 'myFavoriteCustomer'
When I use 'clear all', the input value is updated to 'Customer' (verified via an alert), yet the string displayed in the input value box on the screen is still 'myFavoriteCustomer'.
If I then use the browser's refresh button, the string displayed in the input box is now 'Customer'.
This problem seems to have started when I upgraded to DataTables 1.9.4. I went back to 1.9.0, but the problem seems to persist.
Any thoughts or help would be appreciated.
http://datatables.net/examples/api/multi_filter.html
I took it a step further and implemented a 'clear all' feature that goes through and clears any filters that have been applied to the columns and resets the column's filter value to the value of that column's title.
The code for that is as follows:
[code]
$.fn.dataTableExt.oApi.fnFilterClear = function ( oSettings )
{
/* Remove global filter */
oSettings.oPreviousSearch.sSearch = "";
/* Remove the text of the global filter in the input boxes */
if ( typeof oSettings.aanFeatures.f != 'undefined' )
{
var n = oSettings.aanFeatures.f;
for ( var i=0, iLen=n.length ; i 7){j = i - 3;}
alert("oSettings.aoPreSearchCols[i].sSearch.length for i = " + i + " is " + oSettings.aoPreSearchCols[i].sSearch.length);
alert("cleaning up for j = " + j);
oSettings.aoPreSearchCols[i].sSearch = "";
$("thead input")[j].value = $("thead input")[j].title;
$("thead input")[j].className = "search_init";
alert("oSettings.aoPreSearchCols[i].sSearch is '" + oSettings.aoPreSearchCols[i].sSearch + "'");
alert("$(thead input)[j].value is " + $("thead input")[j].value);
}
}
/* Redraw */
oSettings.oApi._fnReDraw( oSettings );
alert("oSettings.aoPreSearchCols[3].sSearch is '" + oSettings.aoPreSearchCols[3].sSearch + "'");
};
[/code]
The problem is that it's clearing the search string that was in the value and setting the value parameter to the value of the title parameter -- just as expected -- however, when the table is redrawn, the old search string is still displayed in the input box. The value for that input box has been reset though because if I choose 'clear all' again, the sSearch.length for that column is zero.
I've found that if I hit 'clear all' and the table is redrawn and it still shows the previous search value, if I then use the browser's refresh option the input value is corrected.
Here's an example:
I have column 3 that is my customer's names. The input value is 'Customer' which is displayed in the input box and the title is also 'Customer'.
When I search for 'myFavoriteCustomer', the input value is 'myFavoriteCustomer'
When I use 'clear all', the input value is updated to 'Customer' (verified via an alert), yet the string displayed in the input value box on the screen is still 'myFavoriteCustomer'.
If I then use the browser's refresh button, the string displayed in the input box is now 'Customer'.
This problem seems to have started when I upgraded to DataTables 1.9.4. I went back to 1.9.0, but the problem seems to persist.
Any thoughts or help would be appreciated.
This discussion has been closed.
Replies