Allow sorting grouped table rows and reverting to ungrouped state #1072
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
#1064 Sorting has no effect when used with row grouping
Summary:
sortsand column header sorting do not change the order of grouped rows in any wayWhat is the new behavior?
Grouping is applied to the sorted
internalRowsrather than the rawrowsinput so any changes to sorting can affect the order of groups and of rows within groups.Setting
groupRowsBytonullwill remove all row grouping. Care has been taken to allow thengx-datatable-group-headermarkup shown in examples to not throw errors when rows are not grouped.Rows are sorted lazily via accessors, so rapid changes to
sortsandgroupRowsBymay not incur as much overhead since they now just invalidate the sorted rows. Once sorted and grouped the rows are cached for subsequent access until invalidated.Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Tables with grouped rows for which sorting should not be allowed will need to set
externalSortingtotrueas rows will now automatically sort in response to user interaction with the column headers. Perhaps someone noticed and wanted this behavior.Setting the
groupRowsByinput tonullwill immediately remove any information about grouped rows, including anything set by thegroupedRowsinput. Previously, it may have been possible to set bothgroupedRowsandgroupRowsBythen remove the latter, retaining the originalgroupedRows. However, this seems like a strange use case.Other information:
This addresses the question of how sorting should be handled when rows are grouped in only the most basic fashion. Grouped rows are always derived from the result of sorting the rows according to
sorts. Therefore, changing the sort order of columns can change the order of groups since group order is determined by the position of the first row exhibiting that group trait.A few alternate sort methods when rows are grouped:
groupRowsBy = nullto disable row grouping when sorting on other columns (this PR makes this possible) so that the sort applies to all rows without groups.externalSortingwhen sorting on other columns and sort rows with respect to the groups.externalSorting = trueand ignore sorting events to disable sorting