Serverside sort by attribute

Serverside sort by attribute

mattctmattct Posts: 9Questions: 6Answers: 0

Hi -

I'm looking to sort a table by date, however the date output format is not suitable for sorting.

How can I return json data from the server to sort by timestamp, but output the date in the format I require?
Are there additional attributes i can return with the data?

I see this can be done when outputting the data as html
https://datatables.net/forums/discussion/comment/141467/#Comment_141467

Thanks

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    You can use HTML5 attributes - see example here. That would be the way to go,

    Colin

  • l0ckm4l0ckm4 Posts: 4Questions: 2Answers: 0

    this may help as your table source is json.

    $('#products').dataTable({
      /* */
      'createdRow': function(row, data, dataIndex) {
          var $dateCell = $(row).find('td:eq(0)'); // get first column
          var dateOrder = $dateCell.text(); // get the ISO date
          $dateCell
              .data('order', dateOrder) // set it to data-order
              .text(moment(dateOrder).format('DD/MM/YY')); // and set the formatted text
      }
    });
    
This discussion has been closed.