Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get filtered Data result set from jQuery Datatable

It would be great if someone help me on the issue.

I am just trying to get the filtered result set from the Datatable.

Below is my code.

var filtered_row_data = $('#example').DataTable().column(1).search('186').data().unique().sort();

 console.log(JSON.stringify(filtered_row_data));

It just returns all the rows instead of filtered values.

I am using latest stable version of Datatable.

Can anyone please help on this?

like image 479
Raja Avatar asked Oct 16 '15 11:10

Raja


People also ask

How to get filtered data from DataTable in jquery?

var filtered_row_data = $('#example'). DataTable(). column(1).search('186'). data().

What is FN DataTable ext search push?

fn. dataTable. ext.search . This is an array of functions (push your own onto it) which will will be run at table draw time to see if a particular row should be included or not. This example shows a search being performed on the age column in the data, based upon two inputs.


1 Answers

see dataTables selector-modifiers. You are looking for {filter : 'applied'} :

table.on('search.dt', function() {
    //number of filtered rows
    console.log(table.rows( { filter : 'applied'} ).nodes().length);
    //filtered rows data as arrays
    console.log(table.rows( { filter : 'applied'} ).data());                                  
})  

demo -> http://jsfiddle.net/h4wrmfx3/

like image 137
davidkonrad Avatar answered Sep 16 '22 14:09

davidkonrad