How store all data in javascript array after column search?
How store all data in javascript array after column search?

I have tables exactly as described in https://datatables.net/examples/api/multi_filter.html. My code structure is exactly the same (please see the full code and demo using the link).
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable();
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
Now I want to return all records (rows) in the table after performing the search operation, either through console.log()
or save the data in javascript array.
For example after I search Accountant in Position
column, I want to get the whole data stored in javascript array
[[Airi Satou,Accountant,Tokyo,33,2008/11/28,$162,700],
[Garrett Winters,Accountant,Tokyo,63,2011/07/25,$170,750]]
I have tried something like console.log( table.row( this ).data() );
but didn't work. How to achieve this?
Answers
You need to use
selector-modifier
withrows()
, so something liketable.rows({search: 'applied'}).data().toArray()
Colin
Where should I put it? after
.draw()
? I'm new in datatable, it will take me sometime to fully understand the architectureIt doesn't matter, the search will be applied before the
draw()
- so just place it wherever you want to get the filtered data. See example here.Colin