$.fn.dataTable.ext.search not working after call ajax reload for table

$.fn.dataTable.ext.search not working after call ajax reload for table

just3fjust3f Posts: 2Questions: 1Answers: 0

I have strange issue.
I have filter $.fn.dataTable.ext.search.push({}) and it works fine. But after call on table ajax.reload function this filter is stop working.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Thanks for your question. I'm not sure why that would happen.

    As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Allan

  • just3fjust3f Posts: 2Questions: 1Answers: 0

    I have 2 tables. And function which called after click button for hide or show some rows.
    But after i called ajax reload function for this tables button have stopped work.
    Before reload table all works good.

    Function for hide or show rows:

        self.isHide = function (isHide) {
        var workData = null;
        var rowData = null;
    
        if (isHide == true) {
            $.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {
                if (settings.nTable.getAttribute('id') != "work-manage-work-tab-grid" && settings.nTable.getAttribute('id') != "work-manage-servicing-tab-grid") {
                    // if not table should be ignored
                    return true;
                }
                if (settings.nTable.getAttribute('id') == "work-manage-work-tab-grid") {
                    workData = window.WorkTabGrid.workData;
                    rowData = window.WorkTabGrid.table.row(dataIndex).data();
                }
                if (settings.nTable.getAttribute('id') == "work-manage-servicing-tab-grid") {
                    workData = window.ServicingTabGrid.workData;
                    rowData = window.ServicingTabGrid.table.row(dataIndex).data();
                }
    
                var flag = false;
                console.log(workData)
                if (rowData) {
                    if (workData.Type == 2 || workData.Type == 4 || workData.Type == 6) {
                        if (rowData.IsNew == true || (rowData.Notes != null && rowData.Notes != "")) {
                            flag = true;
                        }
                    }
    
                    if (workData.Type == 6) {
                        if (rowData.PassFail == "F") {
                            flag = true;
                        }
                    }
    
                    if (workData.Type == 2) {
                        if (rowData.RequiredServiceLevel != null) {
                            flag = true;
                        }
                    }
    
                    if (workData.Type == 4) {
                        if (rowData.ServiceLevelDone != null) {
                            flag = true;
                        }
                    }
                }
    
                return flag;
            });
            window.WorkTabGrid.table.draw();
            window.ServicingTabGrid.table.draw();
        } else {
            $.fn.dataTable.ext.search.pop();
            window.WorkTabGrid.table.draw();
            window.ServicingTabGrid.table.draw();
        }
    }
    
  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    I can only guess that the pop() call is being run and thus the filter removed. However, without a test case as I asked for before I really can't know for sure.

    Allan

This discussion has been closed.