sortInfo does not work

1.5k views Asked by At

I am trying to display data from table in sorted way. I want to display content ordered by creation date. I add sortInfo, but it does not work! I use angular ui-grid. Here is my code

$scope.gridOptions = {
    enableSorting: true,
    columnDefs: [      
    { field: 'name'},
    { field: 'age'},
    { field: 'creationDate', cellFilter : "date:'yyyy-MM-dd'"}
    ],
    sortInfo: {
        fields: ['creationDate'],
        directions:['desc']
    } 
};

Is it possible to set sort by default here? And how to do it?

I didn't found in ui-grid docs sortInfo option.

1

There are 1 answers

0
Kathir On BEST ANSWER

Your gridOptions is not set right. You need to add the sort property to your column definition like below, the priority is what makes it sort by default. Lower priority gets sorted first. Read more here http://ui-grid.info/docs/#/tutorial/102_sorting

$scope.gridOptions = {
    enableSorting: true,   
    columnDefs: [
      {
        field: 'name',
        sort: {
          direction: uiGridConstants.DESC,
          priority: 1
        }
      }
   }