Need help in sorting using Numeric and Date
Need help in sorting using Numeric and Date
dannjoroge
Posts: 6Questions: 4Answers: 0
i need help in sorting my dataTable i want to sort a numeric column and when i use the below code the numbers don't sort in the right order. i have also tried sorting using date also seems not to work. am using datatables.js version 1.10.12 my jquery is version 2.2.3
this is what i tried seems not to work am getting my data from php and encoding it to json
my table
<table id="datatable-responsive" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Transaction ID</th>
<th>Payment Status</th>
<th>Order No</th>
<th>Amount</th>
<th>Payer</th>
<th>Date</th>
</tr>
</thead>
<tbody id="homework_tbl">
</tbody>
</table>
datatable js
<script type="text/javascript">
$(document).ready(function () {
$('#datatable-responsive').DataTable({
"ajax": '../tables/allpayments.php',
"processing": true,
"fixedHeader": true,
"serverSide": true,
"columnDefs": [ { "type": "numeric", "targets": 0 } ],
"order": [[ 0, "desc" ]],
dom: 'C<"clear">lfrtip'
});
var dt = $('#datatable-responsive').DataTable();
//hide the first column
dt.column(0).visible(false);
});
</script>
This discussion has been closed.
Answers
The sorting is performed by the server-side script, not by DataTables with this parameter enabled. So whatever your
allpayments.php
script is doing it needs to implementing paging, sorting and filtering - see the manual.Do you really need server-side processing? Do you have >25k rows?
Allan
yes i do have thousands of rows. am not able to order by desc from the server side am using php
If you are using server-side processing, you really don't have any choice as to where you do the sorting - it has to be at the server if you want sorting. Why can't you sort descending there?
Allan
so.. its not possible then do the kind-of columns.type on ServerSide?
Sure - but the client-side aspect has no effect on it. Typically your SQL server will sort the way you want (e.g. a number data type will be sorted numerically, date chronologically, etc). If you are using server-side processing it is up to the server-side how to sort the data.
Allan