Does DataTable sort on value of data or rendered representation?

Does DataTable sort on value of data or rendered representation?

sjordansjordan Posts: 3Questions: 2Answers: 0
edited August 2017 in Free community support

Example:

I have data coming from server via ajax in the form:

{
    "data": [{
        "DT_RowId": "row_1",
        "comment": "Doing Well",
        "due_date": 1450790180000,
        "commenter": "Joe Blogs"
    }, {
        "DT_RowId": "row_2",
        "comment": "try harder",
        "due_date": 1503407780000,
        "commenter": "Mary Smith"
    }]
}

due_date are int (milliseconds since epoch)

In my DataTables options, I'm using a render function on the due_date column as follows:

function ( data, type, row ){
  return (data) ? new Date(data).toDateString().slice(4) : 'No Due Date'
}

The result is my int values get rendered as I want (nice human-readable format of my choosing):

1450790180000 => Dec 22 2015
1503407780000 => Aug 22, 2017

However, sorting is not working as expected. The column gets sorted alphabetically

This suggests to me that the sorting functionality of DataTables works on what is rendered to the table, rather than the data that drives the table (the actual source data)

This question has accepted answers - jump to:

Answers

This discussion has been closed.