Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data table specific column filter with multi select drop down

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.

like image 733
Raja Avatar asked Dec 15 '14 08:12

Raja


1 Answers

After long search, I found a solution for this. Actually it was very simple. Below is my fix for this option.

There was already 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 separated. 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.

like image 50
Raja Avatar answered Sep 30 '22 15:09

Raja