Sort the datatable only of rows with available data not whole table

Sort the datatable only of rows with available data not whole table

vipinranavipinrana Posts: 2Questions: 1Answers: 0

Iam firing an event to get API on the drawcallback after the datatable got data list. Also what i does that it keep check if current showed page has loaded and if the column data is loaded and column (say A) value is updated, it will sort accordingly by that column . Initially on datatable A column has value of zero.
Below is the code which Iam using for sorting.
let table = $('#comparison-table').DataTable();
let page_order = table.order();
table.order(page_order).draw(false);

My issue is once i click the sorting icon, above code runs again after the order.dt events. So, is there a way to sort by only available data.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @vipinrana ,

    I'm not following what you mean by 'available data'. The drawCallback is called on every draw - so when you order, page or search. It would be worth looking at all the events to see if another is more appropriate, possibly the xhr if your data is coming via ajax.

    Cheers,

    Colin

  • vipinranavipinrana Posts: 2Questions: 1Answers: 0

    Could it be possible to sort the page according to current page data ?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The sorting is always across the table as a whole - so you can't just sort in isolation on the displayed page.

This discussion has been closed.