Friday, February 8, 2019

DataTable table order by numeric, not by text



DataTable order default by text, i.e 1, 11, 2,3,4,5,6...
I need the order numeric, i.e. 1,2,3,4,5,6,11
Using                                       
                       "columns": [
                                         { "orderDataType": "dom-text", "type": "numeric" }
                                       ],

Example:
         table= $("#result").find('#'+tableId).DataTable( {
                                         destroy: true,
                                        paging: false,
                                        "columns": [

                                         { "orderDataType": "dom-text", "type": "numeric" }
                                       ],
                                    fixedHeader: true
                                } );

Reference:
https://datatables.net/reference/option/columns.orderDataType
Example1:
$('#example').dataTable( {
  "columns": [
    null,
    null,
    { "orderDataType": "dom-text" },
    { "orderDataType": "dom-text", "type": "numeric" },
    { "orderDataType": "dom-select" },
    { "orderDataType": "dom-checkbox" }
  ]
} );
Example2:
$('#example').dataTable( {
  "columnDefs": [
    { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
    { "type": "numeric", "targets": 3 },
    { "orderDataType": "dom-select", "targets": 4 },
    { "orderDataType": "dom-checkbox", "targets": 5 }
  ]
} );
 

No comments:

Post a Comment