Sorting On Original Column Data

Sorting On Original Column Data

Drum998Drum998 Posts: 14Questions: 6Answers: 0
edited October 2016 in Free community support

Hi,

I have a datatable where one of the columns contains a date which needs to be sortable. The data stored in the db for this date is a unix timestamp. I am formatting this to something more friendly using a render function and moment.js

My question is how can I make the date column sort using the original unix timestamp rather than the rendered human readable date?

my column definitions look like this:

    columns: [
        { data: 'jobId' },
        { data: 'venueId'},
        { data: 'bookingDate', render: function ( data, type, row ) {
            var thisDate = moment(data * 1000).format('MMMM Do YYYY');;
            return thisDate;
        }},                                     
        { data: 'bookingTime',"bSearchable": false},
        { data: 'catalogue', "bSearchable": false},
        { data: 'jobStatus',"bSearchable": false}
    ],

This question has an accepted answers - jump to answer

Answers

  • JCFMachadoJCFMachado Posts: 3Questions: 0Answers: 1
    Answer ✓

    I solved this returning two columns from the data source, one for diplaying and one for sorting:

    columns: [
        { data: 'jobId' },
        { data: 'venueId'},
        { data: {
                  '_':'bookingDate',
                  'sort':'bookingDate',
                  'display':'bookingDateDisplay'}
        },                                     
        { data: 'bookingTime',"bSearchable": false},
        { data: 'catalogue', "bSearchable": false},
        { data: 'jobStatus',"bSearchable": false}
    ],
    
This discussion has been closed.