Anonymous
Anonymous

Reputation: 3414

Using ui-grid, how to resume default sort when other sorts removed

I'm using UI-Grid 3.0 (http://ui-grid.info/). I’d like to indicate to the user that there is a default sort applied to the data, but hide that default sort while the user is sorting by some other column. If they remove their custom sort, I want to resume the default sort. But I only want one column to be sorted-by at any time, to keep the UI simple for our users.

My goal is to make the state of the table clear to the user. The table is in fact originally sorted by some column, but unless I specify that as an initial sort ui-grid obviously doesn't know that and can't display it. The best way for a user to understand the default sort is for that sort to appear the same as if any other column were sorted.

The problem is, if the user sorts by any other column, the sort on the original column is removed, and after several clicks the user can get themselves into a state where there appears to be no sort order on the table. I could set suppressRemoveSort: true, but then the user will see two sorts, one primary and one secondary, with a more complex UI. I'd rather hide the first sort and only show the user's selected sort, until they remove that sort, at which point I would want to show the original sort.

My current plan is to investigate external sorting and in particular the sortChanged event to see if I can remove my initial sort when the user sorts by another column, and add back my default sort when the user removes their own sorting choice.

Upvotes: 0

Views: 1956

Answers (1)

Anonymous
Anonymous

Reputation: 3414

I'll edit this answer when I confirm the following.

It appears I'll be able to call grid.sortColumn (mentioned here on StackOverflow) to re-set the default sort column when the sort settings are changed. Users of UI Grid 3.0 can register a callback for that event by defining:

$scope.gridOptions = { onRegisterApi: function( gridApi) { gridApi.core.on.sortChanged($scope, eventHandler); } }.

The eventHandler will be called with grid and sortColumns.

Upvotes: 0

Related Questions