21

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?

2 Answers 2

61

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/

Sign up to request clarification or add additional context in comments.

8 Comments

its work but when i use it twice!, strange, when i hit search button and console it, its show me 10 record but when i hit search again its show me 3 (which is correct no). can you please help to fix this?
@Rohit, can you reproduce this in a fiddle? Tried the answers fiddle above, it seems to work as expected.
as per your suggestion this is my fiddle jsfiddle.net/RohitSavaliya2010/sz7w5uvr/1 can you please check it?
@Rohit, well, it does not work, just some code out of context :) You can grab the above jsfiddle.net/h4wrmfx3 and add / modify then update or fork.
@Manza follow the link to datatables.net/reference/type/selector-modifier (the same as in the answer)
|
0

if you are using server side filtering / searching, this is the only solution i found and it works: xhr event

$('#yourTable').on('xhr.dt', function ( e, settings, json, xhr ) {
        //the new data is here json.data
        console.log(json.data);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.