ColumnFilterWidgets
ColumnFilterWidgets copied to clipboard
ResetAllFilter button issue
Hi, I used the code of ResetAllFilters from https://github.com/cyberhobo/ColumnFilterWidgets/issues/1
But the problem i am facing now is that my filters are not getting reset. The filter select-list from which i choose filter-term , on click of ResetAllFilters button these terms don't get reinserted into the select-list of that filter.
What i am doing wrong? Here is the code.
$.fn.dataTableExt.oApi.fnResetAllFilters = function (oSettings, bDraw) { for(iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) { oSettings.aoPreSearchCols[ iCol ].sSearch = ''; } $('.filter-term').remove(); oSettings.oPreviousSearch.sSearch = ''; if(typeof bDraw === 'undefined') bDraw = true; if(bDraw) this.fnDraw(); }
// button click event $("button").click(function(e){ e.preventDefault(); // 'myDataTable' is the name you gave the datatable at initialisation - oTable or similar $('#example').dataTable().fnResetAllFilters(); });
in datatables 1.10.3
add this to ColumnFilterWidgets.js
// reset
$.fn.dataTableExt.oApi.fnFilterClear = function (oSettings) {
var i, iLen;
/* 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 (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 (i = 0, iLen = oSettings.aoPreSearchCols.length; i < iLen; i++) {
oSettings.aoPreSearchCols[i].sSearch = "";
}
/* Redraw */
oSettings.oApi._fnReDraw(oSettings);
};
add button:
<button id="reset">Reset</button>
table and click func to button:
var table = $('#example').dataTable({
"paging": true,
"searching": true,
"info": true,
"bStateSave": true,
"dom": 'W<"clear">lfrtip'
});
$("#reset").click(function (e) {
table.fnFilterClear();
})