Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grid] vaadin-grid-sorter feature request: bi-state sorting #2018

Open
n1ywb opened this issue Oct 30, 2017 · 6 comments
Open

[grid] vaadin-grid-sorter feature request: bi-state sorting #2018

n1ywb opened this issue Oct 30, 2017 · 6 comments
Labels
enhancement New feature or request vaadin-grid

Comments

@n1ywb
Copy link

n1ywb commented Oct 30, 2017

Our UX designers identified the current tri-state sort behavior (asc, desc, null) as potentially confusing for users and asked me to make is so that once a column is clicked for sorting, clicking the sort button toggles between asc and desc. Clicking another column in single sort resets the first column to null sort. We do not use multi-sort.

This should be rather easily accomplished with the addition of a bi-state property and a slight change to https://github.com/vaadin/vaadin-grid/blob/master/vaadin-grid-sorter.html#L208

If there's sufficient interest from Vaadin I can talk to my boss about getting that coded up. For now I have just monkeypatched the sorter in my app.

@jouni
Copy link
Member

jouni commented Oct 30, 2017

I think this would be a welcome enhancement.

We chose to tri-state by default because it covers the broader use case. But I do understand that this depends on the desired UX for the app, and sometimes tri-state is not suitable.

Did you already have an API in mind, how this would be configured?

@tomivirkki
Copy link
Member

The following should also do the trick:

grid.addEventListener('sorter-changed', e => 
                    e.target.direction = e.target.direction || 'asc');

@n1ywb
Copy link
Author

n1ywb commented Oct 31, 2017 via email

@n1ywb
Copy link
Author

n1ywb commented Oct 31, 2017 via email

@tomivirkki
Copy link
Member

I tried that first but it sets every column to ascending when the elements
are created which should not be allowed to happen unless multisort is
turned on

You can ignore the initial sorter-changed event:

grid.addEventListener('sorter-changed', e => {
  if (e.target._initialized && !e.target.direction) {
    e.target.direction = 'asc';
  }
  e.target._initialized = true;
});

@n1ywb
Copy link
Author

n1ywb commented Oct 31, 2017

@tomivirkki thanks for that, seems a bit cleaner than my monkeypatch.

Upon further testing that solution still seems to force multisort. Previously sorter cols do not return to null sort state when a new column is sorted.

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-grid May 26, 2021
@vaadin-bot vaadin-bot added enhancement New feature or request vaadin-grid labels May 26, 2021
@web-padawan web-padawan changed the title vaadin-grid-sorter feature request: bi-state sorting [grid] vaadin-grid-sorter feature request: bi-state sorting May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vaadin-grid
Projects
None yet
Development

No branches or pull requests

4 participants