Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Select box outside to filter dataTables?

I'm using the DataTables Table plug-in for jQuery but I'm having trouble getting the global input search box would be an select box.

With the sDOM option lrtip, filtering input is not show but is it possible to display select box and getting the datatable to filter based on the change of the select box?

JS:

$(document).ready(function() {
    var table = $('#table_page').DataTable( {
        paging:   true,
        ordering: false,        
        info:     true,
        searching: true, 
        sDom: "lrtip" // default is lfrtip, where the f is the filter
    });
});

HTML:

<table id="table_page" class="display cell-border" width="100%">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
    </thead>
</table>
like image 921
LeMoussel Avatar asked Oct 26 '16 13:10

LeMoussel


1 Answers

You can use search() API method to perform global search programmatically and dom option to disable built-in search control.

For example:

var table = $('#example').DataTable({
   dom: 'lrtip'
});

$('#table-filter').on('change', function(){
   table.search(this.value).draw();   
});

See this example for code and demonstration. See this example, if you want to replace default search box.

like image 198
Gyrocode.com Avatar answered Sep 28 '22 09:09

Gyrocode.com