order() without draw()

order() without draw()

YanKonYanKon Posts: 2Questions: 1Answers: 0
edited July 2018 in Free community support

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' ] );

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());


  • colincolin Posts: 3,648Questions: 0Answers: 645

    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.



  • YanKonYanKon Posts: 2Questions: 1Answers: 0

    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




  • allanallan Posts: 48,908Questions: 1Answers: 7,131 Site admin

    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();.


Sign In or Register to comment.