order() without draw()
order() without draw()
YanKon
Posts: 2Questions: 1Answers: 0
Hey,
is it possible to order the table but not output it again?
Because when I run the code below I always got the original order (column 0):
var table = $('#example').DataTable();
table.order( [ 1, 'asc' ] );
console.log(table.columns([0,1]).data());
I'd like to do some calculations in the background.
Thank you
edit: same problem with this code:
var table = $('#example').DataTable();
console.log(table.order( [ 1, 'asc' ]).columns([0,1]).data());
This discussion has been closed.
Answers
Hi @YanKon ,
You need the draw to change the table - but if you just want to get an ordered array of column data for your background calculations, you can use
sort()
instead. This will order your data array, but not affect the table.Cheers,
Colin
Hey Colin,
but how can I sort the data with the second column?
For example:
I get with the command below, an array with two arrays. Now I want to sort both inside arrays with the second column
Cheers,
Yannick
Assuming you want to sort the data and not the table as Colin said, you'd need to pass in a sorting function to the
sort()
method. See the MDN documentation for how to use a compare function for an array sort.If you just want the DataTable to order the data over two columns do
table.order([[0,'asc'], [1,'asc']]).draw();
.Allan