sortable date column

sortable date column

SomeNameSomeName Posts: 1Questions: 0Answers: 0

I was wondering if there is a way to insert date instance in a column and retain the sorting order.
In the dataSrc function, i convert json into a valid Date object:

However, when i specify column type of date, it prints and invalid date error.
The dataSrc function could convert date into a date formatted string, however, if we do that, the date order will not be retained. Does datatable have any way of consuming a date like object that can be formatted as well as date sort order being retained ?

Code:

function populateTableAjax(api) {
    $('#example').DataTable({
        'ajax': {
            "type": "GET",
            "url": api,
            "dataSrc": modifySuiteData
        },
        "columns": [{
            "data": "start_time"
        }],
        "columnDefs": [{
            "title": "Start Time", "targets": 0, "type": "date"
        }]
    });
}


function modifySuiteData(original_json) {
    var return_data = new Array();
    for(var i = 0; i < original_json.length; i++){
        return_data.push({"start_time": new Date(original_json[i].start_time)})
        //original_json[i].start_time = new Date(original_json[i].start_time)
    }
    console.log("comes here " + Date(return_data[0].start_time));
    return return_data;
}

Console :
comes here Sun May 07 2017 21:37:14 GMT-0700 (PDT)

Thanks.

Replies

This discussion has been closed.