I use jQuery datatables plug-in and pass data through JSON array. In my table I have a Date
column and that column has different date format like "Mon , 02 Sep 2019", so sorting doesn't work on this date column properly.
I have read about HTML5 data-sort
attribute which is data table code they have mentioned in their documentation but I don't have any idea how to use this data-sort
attribute with JSON array.
My code so far is:
$(document).ready(function() {
$('#example').DataTable({
"order":[],
data : [['TEST','Develper','ABC','25','Mon , 05 Aug 2019','100000'],['TEST','Develper','ABC','25','Tue , 06 Aug 2019','100000'],['TEST','Develper','ABC','25','Mon , 02 Sep 2019','100000'],['TEST','Develper','ABC','25','Mon , 14 Oct 2019','100000'],['TEST','Develper','ABC','25','Mon , 04 Nov 2019','100000'],['TEST','Develper','ABC','25','Mon , 01 Nov 2020','100000']]
});
} );
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.18/rg-1.1.0/datatables.min.css" />
<script type="application/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.18/rg-1.1.0/datatables.min.js"></script>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
</table>