带有多选下拉菜单的数据表特定列过滤器 [英] Data table specific column filter with multi select drop down

查看:17
本文介绍了带有多选下拉菜单的数据表特定列过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Datatable API 中看到了这种可能性,用于使用 Drop down 进行特定的列过滤.

I have seen this possibility in the Datatable API for the specific column filtering with Drop down.

参考:https://datatables.net/examples/api/multi_filter_select.html

但对我来说,它的不同,我需要对多选下拉菜单做同样的事情.所以数据表应该相应地显示结果.

But for me, its different, I need to do the same with multi-select drop down. So the datatable should show the results accordingly.

因此在上面的链接中,我无法选择两个办公室东京和伦敦".我已经使用多选插件实现了编码(http://harvesthq.github.io/chosen/) 但数据表只有一种选择.

So as in the above link, I can not able to select two offices "Tokyo and London". I had implemented the coding with multi-select plugin (http://harvesthq.github.io/chosen/) but the datatable takes only one option.

这可能吗?如果可以,请帮忙解决这个问题.

Is that possible? If so can you please help on this.

推荐答案

经过长时间的搜索,我找到了解决方案.

After long search, I found solution a solution for this.

其实很简单.以下是我对此选项的修复,

Actually it was very simple. Below is my fix for this option,

已经有一个选项可以根据以下链接搜索特定的列虎钳,

Already there was an option to search for specific column vise as per the below link,

http://www.datatables.net/examples/api/multi_filter.html

   // DataTable
    var table = $('#example').DataTable();

    // 2 is column id 
    // "India" is search string
    table.column( 2 ).search( 'India' ).draw(); 

So the above one will search for "India" in a specific column "2" (Say like "Country" column)

Here i need an ability to search for more than one country like "India, Japan etc.,"

So the code will be as follows,

        // DataTable
        var table = $('#example').DataTable();

        // 2 is column id 
        // "India|Japan|Spain" is search string
        table.column( 2 ).search( 'India|Japan|Spain', true, false ).draw(); 

    Updated: We need to add two more parameters in the "search()" function.

    search(val_1,val_2,val_3)

    where,
    val_1 is search string with "|" symbol seperated. So it contains regular express chars as per the example. 
    val_2 is true (To enable regular express in the search)
    val_3 is false (To disable smart search. default is true)

参考:https://datatables.net/reference/api/search()

所以我刚刚在搜索字符串之间添加了一个管道"符号:p LOL

So I have just added a "pipe" symbol between the search strings :p LOL

这篇关于带有多选下拉菜单的数据表特定列过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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