3

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
  • Are you wanting the grid to initialize with that column sorted or are you wanting to dynamically sort it at some random point down the road? Commented Jun 10, 2015 at 17:34

1 Answer 1

16

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.