Angularjs ui-grid sorting table according to a given column name

14.5k views Asked by At

I am using ui-grid version v3.0.0-rc.21-1d9f81f - 2015-05-01 and trying to sort a given grid according to a given column name. I cannot sort it externally (from javascript code), only by defining it and by clicking on the grid's headers.

Is it possible in this version to sort the grid's data according to the grid's column name via javascript code?

1

There are 1 answers

0
Kathir On BEST ANSWER

If you want to sort it just based on a column/field before the grid is loaded, you can do so just by using the angular orderBy filter whenever your data is retrieved from the server.

$filter('orderBy')(array, expression, reverse)

Or If you wanted to sort the grid at the initial state, you can define it in the columnDef with the sort property

{
            field: 'gender',
            sort: {
              direction: uiGridConstants.ASC,
              priority: 0,
            }
}

Take a look at this plnkr http://plnkr.co/edit/4qQgi76RQpYxbRgbcByX?p=preview