重置数据表中的过滤数据 [英] Reset filtered data in DataTables

查看:22
本文介绍了重置数据表中的过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,其中使用 AJAX 检索数据.然后我有两个搜索功能来过滤数据.一旦处理未过滤的数据,搜索功能就可以正常工作.应用过滤器后,我无法清除过滤器或应用另一个过滤器,因为这两个过滤器是相互排斥的(一个过滤器是全部付费的,另一个是全部未付费的).我认为我的问题是,一旦数据被过滤,然后我尝试清除或应用另一个过滤器,它就会作用于数据的一个子集(已经过滤的数据).如何在应用新过滤器之前清除重置过滤的数据以及如何重置过滤器.我已经在这个网站上尝试了一些解决方案,但它们没有用.这是我的过滤器功能.

I have a Datatable where the data is retrieved using AJAX. I then have two search functions that filter the data. The search functions work fine once working with unfiltered data. Once a filter is applied, I am unable to clear the filter or apply the other one as both filters are mutually exclusive (One filter is All Paid and the other is All Unpaid). I think my issue is that once the data is filtered then I try to clear or apply another filter, it is acting on a subset of the data (the already filtered data). How do I clear reset the filtered data before I apply a new filter and how do I reset the filters. I have tried a few solutions already on this site but they did not work. Here are my filter functions.

function outstandingFees() {


$.fn.dataTable.ext.search.push(

    function (settings, data, dataIndex) {

        var zero = 0;
        var fee = parseFloat(data[8]) || 0; // use data for the balance due column

         if (fee > zero) {
            return true;
        }

        return false;

    }

);

table.draw();

}


function paidFees() {

$.fn.dataTable.ext.search.push(

    function (settings, data, dataIndex) {

        var zero = 0;

        var fee = parseFloat(data[8]); // use data for the balance due column


        if (fee === zero) {

            return true;

        }

        return false;

    }

);

table.draw();

}



function allFees() {

$.fn.dataTable.ext.search.push(

    function (settings, data, dataIndex) {

        var zero = 0;

        var fee = parseFloat(data[8]) || 0; // use data for the balance due column

        if (zero <= fee) {

            return true;

        }

        return false;

    }

);

table.draw();

}

推荐答案

正如 davidkonrad 所说

As said by davidkonrad

$.fn.dataTable.ext.search.pop()

为我工作.我只是将它添加到每个方法的顶部,以便在应用新方法之前清除过滤器.

worked for me. I just added it to the top of each method in order to clear the filter before applying a new one.

这篇关于重置数据表中的过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆