Order by Column anomaly

Order by Column anomaly

youngwill4everyoungwill4ever Posts: 1Questions: 1Answers: 0

I have a weird case, at page load, the table is configured to sort by "created date" in desc, but the latest record is not showing at the top. When I sort it by clicking the column header, now it shows. The record can be searched, so it's in the collection but somehow missing from the top upon the initial load.

Here is my configuration for column order:

//6 = created date column index
"order": [[6, "desc"]],

In the document ready event, I load the DataTable(), then :

//default the dta table to pending status
tblNm.columns("status:name").search("Pending").draw();

Everything works and looks right except upon the page load it doesn't display the latest record at the top.

Answers

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769
    edited August 2019

    It could be lots of things. Without actually seeing the problem happen its hard to offer suggestions. The problem could be data specific, due to server side processing or the order of events, to name a few. Can you post a link to your page or a test case replicating the issue?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Some questions:
    1. Do you have server side processing enabled?
    2. Does the order work if you don't use tblNm.columns("status:name").search("Pending").draw();?
    3. What is different about the latest record from the others?

    Some suggestions:
    1. For client side data the recommended solution for date/time sorting is discussed in this blog.
    2. If using server side processing then your server script is response for sorting the data.
    3. Not that it will fix the problem but you might look at the searchCols option to set the initial default search to pending.

    Kevin

This discussion has been closed.