Datatables orthogonal data as date

Datatables orthogonal data as date

ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
edited November 2023 in General

Hi,

link to test case : https://live.datatables.net/timilitu/200/edit

I have a datatables set up with data from a json file. I this json file, my date are at the format DD/MM/YYYY but i also have string in the same column (only "N/A" as value but still a string and not a date). What i want to do is to i filter and sorting the column like all value are date.

when i do this on my column, the sorting and the filter work correctly but the display value is '01/01/1990' :

render: function(data, type, row) {
                 if (data === 'N/A') {
                     return '01/01/1990';
                 }
                return data;
            }

So then i use orthogonal data set up like this :

render: function(data, type, row) {
                if ( type === 'display') {
                return data
            } else if (data == 'N/A' && type === 'sort' || data == 'N/A' && type === 'filter') {
                return '01/01/1900';
            } 
        return data;
    }

But it doesn't work, the displayed data are ok but the sorting and filtering as a date doesn't work anymore, what i m doing wrong ?

thank you in advance,
Mathieu.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Hi Mathieu,

    It looks like it was just the type === 'type' data type that was missing in the condition: https://live.datatables.net/timilitu/201/edit .

    That request returns the data that DataTables uses for type detection.

    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited November 2023

    thank you it work, it is possible as well that if i write N/A in the searchbuilder, it show all the N/A (value where the date is = '01/01/1900').

    I have a create a custom condition in the searchbuilder script ?

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    If you were to create a custom condition that does that logic, then yes, you can do any filtering you want :).

    Allan

Sign In or Register to comment.