Order by timestamp dataTables Angular js

Asked

Viewed 59 times

0

Good morning wanted to sort a datatable of Angular JS by a column that is a timestamp of descending form and for that I used:

controllerScope.logsData = {
    ajax: {
        url: '/api/organizations/'+$rootScope.organization.id+'/alerts?type=logevent',
        dataSrc: '',
        beforeSend: function (xhr) {
           xhr.setRequestHeader("Authorization", AuthService.authToken());
        }
    },
    columns: [
        {"data":"timestamp", render: function(data,type,row){
            return $filter('date')(row.timestamp, 'dd-MM-yyyy HH:mm:ss');
        }},
        {"data":"data.serial","defaultContent":""},
        {"data":"data.type","defaultContent":""},
        {"data":null, "orderable":false, "render":function(data){
            if(data.data.body){
                return JSON.stringify(data.data.body);
            } else {
                return '';
            }
        }}
     ],
    order: [[0, 'desc']]

However this ordination is not working... Can anyone help?

1 answer

0

An alternative is to change the date mask to:

'yyyy-MM-dd HH:mm:ss'
  • Thank you I’ve already solved

Browser other questions tagged

You are not signed in. Login or sign up in order to post.