How to reset all filters? (DataTable with AJAX sourced data file)

How to reset all filters? (DataTable with AJAX sourced data file)

m1stm1st Posts: 4Questions: 0Answers: 0
edited January 2014 in General
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!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It should still work with Ajax sourced data. Can you link to a test case showing the issue so I can debug it please?

    Allan
  • m1stm1st Posts: 4Questions: 0Answers: 0
    I've found out the root of the problem. It's a button placement in fnInitComplete section.
    [code]
    "fnInitComplete" : function() {
    $("div.buttons")
    .html(
    ''
    + 'Reset All Filters'
    + '');
    }
    [/code]

    Just move it out to solve:
    [code]
    $(".buttons")
    .html(
    ''
    + 'Reset All Filters'
    + '');
    [/code]
This discussion has been closed.