Support in-memory sorting for DataGrid (3389)#5141
Open
Conversation
…t-for-sorting-delegate-in-dataGrid # Conflicts: # jmix-flowui/flowui/src/main/java/io/jmix/flowui/component/grid/DataGridColumn.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes for: #3389
Changes
Sort.ExpressionOrder
Added new type of sort order-
ExpressionOrder.It is supported by
SortJpqlGenerator. The generator checksExpressionOrderand place it as is tosortExpressions. It means thatExpressionOrderskips checks forMetaPropertyPathand does not pass toJpqlSortExpressionProvider.ExpressionOrdercan be used when it is need to sort by specific expression. For instance, for JPQL, the expressions can be:"function('calc_total_sum', {E}.id)";"length({E}.firstName)";"{E}.firstName".ExpressionOrder and KeyValueEntity query
When
ExpressionOrderis used in query which result isKeyValueEntity, theExpressionOrderrequires to use the same entity alias as in a query.For instance:
Query:
select e.name, e.startTime, e.endTime from CarService eThe expression:
length(e.name)Comparator in DataGridColumn
Now, when
DataGridColumnhas custom comparator, it will be used when sorting isin-memory.Note that
in-memorysorting occurs:SimplePagination) and number of loaded items is less than page size.Example of adding comparator:
Sort builder delegate in DataGrid
Added the extension point to customize sort in
DataGrid. For instance:When this feature may be used:
Sample 1. Override sorting for JPA entity property
Let's imagine that some entity property with String type stores integer values.
By default, this property is sorted as String values:
Let's make sorting to sort by number values as follows:
We have provided sorting for
in-memoryand for persistent (JPQL).Sample 2. Add sorting for column without property.
Let's say we have a column "Full name". It renders concatenated
firstNameandlastNameproperties.In the sort builder delegate we can do the following:
Sort Builder Delegate vs CollectionContainerSorter and JpqlSortExpressionProvider
Use Sort Builder Delegate when sorting must be customized for a specific
DataGrid:Use
CollectionContainerSorterwhen you need to customize container-level in-memory sorting mechanics:CollectionContainer(not only one grid column mapping);SorterFactory(@Primarycustom factory).Use custom
JpqlSortExpressionProviderwhen you need global customization of DB-level ORDER BY expression generation for entity properties:Sort.ExpressionOrder(expression is inserted as-is).In short:
CollectionContainerSorter(+SorterFactoryfor global rollout)JpqlSortExpressionProvider.