How to reset all filters? (DataTable with AJAX sourced data file)
How to reset all filters? (DataTable with AJAX sourced data file)
Hello,
'Reset all filters' script has stopped working after I moved my DataTable from DOM to Ajax file data source.
What's wrong with it? DataTables v1.9.4 is used.
There's the script:
[code]
$("#reset_all_filters").click(function (oSettings, bDraw) {
var oSettings = oTable.fnSettings();
/* 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 < iLen; i++) {
$('input', n[i]).val('');
}
}
/*
* Remove the search text for the column filters - NOTE - if you have input boxes for these filters, these will need to be reset
*/
for (var i = 0, iLen = oSettings.aoPreSearchCols.length; i < iLen; i++) {
oSettings.aoPreSearchCols[i].sSearch = "";
}
/* Redraw */
oSettings.oApi._fnReDraw(oSettings);
$("input[name='InputFieldName']").val('');
$('a.filter-term').click();
});
[/code]
Thank you!
'Reset all filters' script has stopped working after I moved my DataTable from DOM to Ajax file data source.
What's wrong with it? DataTables v1.9.4 is used.
There's the script:
[code]
$("#reset_all_filters").click(function (oSettings, bDraw) {
var oSettings = oTable.fnSettings();
/* 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 < iLen; i++) {
$('input', n[i]).val('');
}
}
/*
* Remove the search text for the column filters - NOTE - if you have input boxes for these filters, these will need to be reset
*/
for (var i = 0, iLen = oSettings.aoPreSearchCols.length; i < iLen; i++) {
oSettings.aoPreSearchCols[i].sSearch = "";
}
/* Redraw */
oSettings.oApi._fnReDraw(oSettings);
$("input[name='InputFieldName']").val('');
$('a.filter-term').click();
});
[/code]
Thank you!
This discussion has been closed.
Replies
Allan
[code]
"fnInitComplete" : function() {
$("div.buttons")
.html(
''
+ 'Reset All Filters'
+ '');
}
[/code]
Just move it out to solve:
[code]
$(".buttons")
.html(
''
+ 'Reset All Filters'
+ '');
[/code]