Fernando_Code
Fernando_Code

Reputation: 63

How to sort a Datatable by Dates (as standart) while keeping the ordering option available for other columns?

I have a table with 6 columns. The 1 and the last ones are dates while the rest numbers. What I am trying to do is sort the table initially (as standard) by dates while offering the possibility for users to also sort by numbers.

The problem is, when I only use ordering= true, the dates dont follow the correct order, therefore I have to use columnDefs : [{"targets":[0,5], "type":"date-eu"}. However, when I do this, the sorting option doesn't work anymore in the other columns. Then I tried to add that: columnDefs : [{"targets":[0,5], "type":"date-eu"}, {"targets":[1,2,3,4],orderable:true}] , but still- nothing.

DO you have any idea how can I solve that?

var table = $('#tbl_compare').DataTable( {
    searching: false,
    lengthChange: false,
    info:false,
    processing: false, 
    columnDefs : [{"targets":[0,5], "type":"date-eu"}, {"targets": [1,2,3,4],orderable:true}],
    order: true,
    iDisplayLength: 10,
    }

Upvotes: 2

Views: 86

Answers (1)

Fernando_Code
Fernando_Code

Reputation: 63

I believe I found a solution order: [];

Upvotes: 1

Related Questions