Datatable Rows getting Shuffled after each ajax reload

Datatable Rows getting Shuffled after each ajax reload

sanath tharunsanath tharun Posts: 3Questions: 1Answers: 0

I am using a datatable. Each time i reload the datatable using ajax, all the rows of datatable are getting shuffled(reordered), whether i make any change or not.
I don't want this to happen. Even after reloading, is there anyway to get rows of datatable without re-ordered?

If I i delete a row, it should go away and all remaining rows should be in same order & if i add any row, it should get added at the end. please suggest a way.
present, i am using "table.ajax.reload(null,false);" to reload using ajax

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Datatables will order the table based on how its sorted. If you add a row it will be displayed in the table based on the order applied. You can turn of Datatables sorting by setting the ordering to false. Datatables will display the table in the order received in the JSON response.

    Kevin

  • sanath tharunsanath tharun Posts: 3Questions: 1Answers: 0

    @kthorngren i tried {"ordering": false} but no use.
    each time there is an ajax reload, rows are getting shuffled. i don't know whether it is problem with ajax call or datatable or database itself.

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited May 2021

    Use the browser's network inspector to look at the JSON response. Compare that to the table order.

    Kevin

  • sanath tharunsanath tharun Posts: 3Questions: 1Answers: 0

    @kthorngren yes sir, just now i inspected it.
    even after invoking ajax.reload, the JSON response in browser's network inspector is same without any change.
    only rows of table are getting shuffled. so no problem with ajax call or DB.

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited May 2021

    Take a look at this example:
    http://live.datatables.net/mucedavu/1/edit

    Both table are fetching the same data. The first is ordering the table and sorted by column 1. The second has ordering: false and the table is in the order received. Even using ajax.reload() the tables are ordered the same.

    There must be something else happening on your page changing the order. Can you post a link to your page or a test case replicating the issue so we can help debug?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.