Preserve sorting after updating a row (I know it been asked before around 2018)

Preserve sorting after updating a row (I know it been asked before around 2018)

YogevYogev Posts: 3Questions: 1Answers: 0

**# Hello all,#
**
First of all, I want to apologize that I am re-asking the same question which was already asked in the past. (https://datatables.net/forums/discussion/48237/preserve-sorting-after-updating-cell)

BUT, more than 3 years have passed since, So I hope this matter has a solution nowadays.

#My use-case:#
**
I have a Datatable that gets real-time updates from a server.
As an update comes to the connected clients the relevant row (
and only it** - without refresh the entire table) is updating right in front of the client's eyes. B) o:)
the code responsible for this magic is this:

**// Variables reference:
**
let tMorning = $('#datatable-morning').DataTable({});

// the crucial code
let row2manipulate = tMorning.row('#row_Id').data();
row2manipulate.rellavantColumn = 'some new data';
tMorning.row('#row_Id').data(row2manipulate).draw();

until here everything works like a charm !!! (thank you for that, datatables.net R&D team!)

**
My actual Issue:
**

after row.data().draw() the table is re-sorts itself.
and this is a functionality I wish to avoid.

needless to state, this is a bad UX for a client.

Thank you so much for any help/suggestion.

Cheers, Yogi.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 12,948Questions: 0Answers: 2,206

    The same would apply as the thread you referenced. Because the data has changed, any draw() would cause the table to apply the current sorting. As Allan said, to keep that row in place you'll need a custom sorting plugin, something like absolute perhaps (example here).

    Colin

  • YogevYogev Posts: 3Questions: 1Answers: 0
    edited July 14

    Thank you, Colin, I appreciate your answer. nevertheless, I think you are wrong mate. there is an option to preserve your sorting.

    tMorning.row('#row_Id').data(row2manipulate).draw('page');
    

    have a lovely day my friend.

  • colincolin Posts: 12,948Questions: 0Answers: 2,206
    Answer ✓

    Gotcha, yep, that will work, I misread your message. Glad you got it sorted - well, not sorted I guess, but you know what I mean! :)

    Colin

  • YogevYogev Posts: 3Questions: 1Answers: 0

    B) :)

Sign In or Register to comment.