check the codedate in date column received and inserted into the datable after initial fill-up of the datable is not sorting!
In my code, I made an HTML page in which I have a data table and I am filling it up with data received from SQL query. once the table is filled with data from the database, I am making an ajax call to another PHP page and received the date of the events listed in the table in JSON format and converted it into javascript object and putting it in a date column in the same table which was filled up before, by writing the ajax call and data table insertion code inside script tag; the dates are inserted but it's not sorting. All these events are happening in the PHP part of my code. Can anybody point out my mistake? how to sort the data after initially filling up the table and then adding into it again in a new column which was not filled before.
Firstly, you need to set the data format within your table by calling the following function in your $(document).ready function (or wherever for that matter, but before datatable gets created):
$.fn.dataTable.moment(format); //format can be anything, like DD/MM/YYYY
You need to have the moment js library for this.
Then, you can use the dataTable api to order by a column in your dataTable creation function. Example:
table = $("#your-table").DataTable(
{
order: [columnNumber, order]
}
)
Where columnNumber is the number of the column you want to order by (it starts with 0) and order is either 'desc' or 'asc'.
Check the api for more information here.