YADCF数据表累积过滤器

时间:2018-05-30 18:30:51

标签: yadcf

我正在使用Datatables服务器端脚本来填充9个YADCF过滤器,它运行良好。我需要做的是使用cumulative_filtering,但我找不到任何关于如何使用服务器端累积过滤以及累积逻辑'可能看起来像。显然,当从其中一个中选择一个值时,我需要更新/重新加载过滤器。我当前的服务器端脚本的一部分如下所示:

$ data [' yadcf_data_6'] = $ db    - > selectDistinct(" table_name",["键入值,键入标签"],null,"键入")    - >使用fetchall();

我的JS看起来像这样:

// YADCF filters Modal  
    $(document).ready(function () {
'use strict';

var oTable;
oTable = $('#table').DataTable();

yadcf.init(oTable,
    [{
                column_number: 6,
                filter_container_id: 'searchtype',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Type'
            },
            {
                column_number: 7,
                filter_container_id: 'searchcategory',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                sort_as: "alpha",   
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Category'
            },
            {
                column_number: 8,
                filter_container_id: 'searchmaterial',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Material'
            },
            {
                column_number: 9,
                filter_container_id: 'searchgrade',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Grade'
            },
            {
                column_number: 10,
                filter_container_id: 'searchshape',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Shape'
            },
            {
                column_number: 11,
                filter_container_id: 'searchcut',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Cut'
            },
            {
                column_number: 12,
                filter_container_id: 'searchsize',
                filter_type: "text",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                filter_match_mode: 'exact',
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Size'
            },
            {
                column_number: 29,
                filter_container_id: 'searchpairs',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Pairs'
            },
            {
                column_number: 31,
                filter_container_id: 'searchset',
                filter_type: "select",
                filter_reset_button_text: "Clear",
                select_type: "chosen",
                select_type_options: {
                'width': '50em',
                },
                filter_default_label: 'Sets'
            }
        ],
    {
        cumulative_filtering: true
    }
);     

});

是否有任何人可以指出的示例代码(我找不到任何代码,我发现并使用了客户端代码here),如果没有,有人可以给我一些提示在哪里开始?

1 个答案:

答案 0 :(得分:0)

逻辑如下

1)每次使用过滤器时,都会向服务器发送一个请求

2)根据该请求,您应该查询您的数据库

3)然后根据查询结果,您应该获得一些数据行

4)基于这些行,您必须从该查询结果填充当前过滤器元素(与非 cumulative_filtering 场景不同,在该场景中,您从DB中存在的整个数据集中填充过滤器元素)