Data table specific column filter with multi select drop down

前端 未结 1 848
醉酒成梦
醉酒成梦 2021-01-13 09:15

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

相关标签:
1条回答
  • 2021-01-13 09:46

    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

    0 讨论(0)
提交回复
热议问题