Grid custom sort

Hello guys,
i have a problem with sorting a column in a vaadin grid.

Here is my code:
grid
.addColumn(“additionalInfoPayer”)
.setSortProperty(“depositInAdditionalInfo.payer”)
.setHeader(PAYER.translated());

As far as im aware, the setSortProperty gets the results from the database and the problem is that this column has empty strings in some cases and these get put on top. How can i make the empty strings go below the records that arent empty ? Is it possible to sort with a custom query in a grid ?

setComparator allows you to create your own comparator with all logic you need.

The suggested setComparator API only makes sense with in-memory data since it needs access to the full data set to compare all the items.

For a lazy loading backend, you need to customize the data provider that you’re using to interpret the sort properties in a way that makes sense with the backend that you’re using. For instance if you’re using a Spring Data repository, then you need to ask yourself how you would make Spring Data fetch data in a way that is sorted according to your needs. Once you know that, then it will probably be relatively straightforward to apply the same also when data is fetched through the grid.

2 Likes