Issues with Clearing Columnar filters

Issues with Clearing Columnar filters

jadhvaryujadhvaryu Posts: 20Questions: 5Answers: 0

Hi!

I have created columnar filters in the second row, below the header row as follows:
// setup the columnar filters
$('#xWMOrderTable thead tr#xWMOrderTableHdrFilter th').not(
":eq(8)").each(
//
function() {
var title = $('#xWMOrderTable tfoot th').eq(
$(this).index()).text();
$(this).html(
'<input type="text" placeholder="Search '
+ title + '" />');
});
// Apply the filter
OrderHdrOutputTbl.columns().eq(0).each(
function(colIdx) {
if (colIdx == 8)
return; // Do not enable search for that column
$(
'input',
OrderHdrOutputTbl.column(colIdx)
.header()).on(
'keydown keyup change',
function() {
OrderHdrOutputTbl.column(colIdx)
.search(this.value).draw();
});
});
//

When a new search is done, i want to ensure that all the previous colmnar filters are resetted and values in the input field are cleared.

I have tried the following code:
function clearTableFilters() {
var oSettings = OrderHdrOutputTbl.fnSettings();

    for (var iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
        oSettings.aoPreSearchCols[iCol].sSearch = '';
    }
    OrderHdrOutputTbl.fnDraw();
    $("#xWMOrderTable").DataTable().search("").draw();
     // Reset Column filtering
    $('#xWMOrderTable thead tr#xWMOrderTableHdrFilter th').val('').change().draw();

    // Reset column order
    OrderHdrOutputTbl.colReorder.reset();
}

None of this code is actually removing the filters nor clearing the input field.

Any ideas would be appreciated.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin
    Answer ✓

    You should absolutely never need to access the options in the settings object. Use columns().search() (e.g. table.columns().search(''); to clear the currently set column filters.

    If that isn't working, we'd need a link to a test page showing the issue.

    Allan

  • jadhvaryujadhvaryu Posts: 20Questions: 5Answers: 0

    Hi Allan,

    realized the filters were clearing but the input field were not getting cleared.

    Through your answer in some other thread, was able to get the issue resolved.

    Thanks!

This discussion has been closed.