sort by date field.. want blanks to be last (latest)

sort by date field.. want blanks to be last (latest)

seamanjeffseamanjeff Posts: 8Questions: 1Answers: 0
edited November 2014 in Free community support

Is there any easy way to achieve this?

I saw some old posts on this but they were never really answered.

Here's a live demo: http://live.datatables.net/mawequma/2/

I'd like the row with the blank date to be at the bottom.

This question has an accepted answers - jump to answer

Answers

  • seamanjeffseamanjeff Posts: 8Questions: 1Answers: 0

    bumping to let you know I added a datatables live demo

  • neilrao42neilrao42 Posts: 14Questions: 2Answers: 1
    edited November 2014 Answer ✓

    You can tell datatables that a empty date should be forced to the end of the table by returning JavaScript's max supported date only for sorting (and an empty string for display and internal data cache):

    var dTabCols = [
        { "sTitle": "WO", "sClass": "WO", "mData": "columns.tranid", "bSortable": false },                                 
        { "sType": "date", "sTitle": "Run Date", "sClass": "Run Date", "mData": "columns.rundate", "bSortable": false, "defaultContent": "", 
    render: function ( data, type, full, meta ) {
          return type === 'sort' && data === '' ?
            new Date(8640000000000000) : data;
    } 
    }
        ];
    

    (Untested. I'm on mobile so I can't format the code properly either.)

  • seamanjeffseamanjeff Posts: 8Questions: 1Answers: 0

    That did the trick: http://live.datatables.net/daluvivo/1/ Thanks, Neil. I will re-read the part of the manual on "orthogonal data" and I'm sure more will sink in now.

  • neilrao42neilrao42 Posts: 14Questions: 2Answers: 1

    No problem :-)

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Nice trick - like it!

    Allan

This discussion has been closed.