Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResetAllFilter button issue #33

Open
hhhjjjkkklll opened this issue Jun 6, 2014 · 1 comment
Open

ResetAllFilter button issue #33

hhhjjjkkklll opened this issue Jun 6, 2014 · 1 comment

Comments

@hhhjjjkkklll
Copy link

Hi, I used the code of ResetAllFilters from
#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();
});

@szakalq
Copy link

szakalq commented Oct 10, 2014

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();
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants