Data table specific column filter with multi select drop down

断了今生、忘了曾经 提交于 2019-12-01 03:43:46

问题


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

Ref: 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.

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.


回答1:


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)

Ref: https://datatables.net/reference/api/search()

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



来源:https://stackoverflow.com/questions/27479868/data-table-specific-column-filter-with-multi-select-drop-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!