Table sorting using "valueCollectionDatasource" not working

I have created a custom search page. Results from DB are displayed in the same page using “valueCollectionDatasource”.

Unfortunately, column sorting is not working on the results table. As on as I click on any of the table columns, the table goes blank and row count at the top right of the table becomes ZERO (‘0 rows’).

Not just sorting, pagination too isn’t working.
Multiselect option is working.

Custom data source definition is as below:
public class RegistrationsDataSource extends CustomValueCollectionDatasource {
protected Collection getEntities(Map<String, Object> params) {
return null;
-------------------------------------------Preformatted text-------------*

Controller code snippet:

	registrationResults.forEach(registration -> registrationsDs.addItem(registration));
	//Setting properties for "registrationsDs"

Hello, @jasvir.singh

Could you share small test project to reproduce the problem?


Thanks Daniil,
Table column sorting is working but the pagination isn’t working even when “maxResults” is set for the datasource.

Is pagination not working only for ValueCollectionDatasource or it’s not working at all?

Hi @jasvir.singh,

Pagination for custom data sources should be implemented explicitly by yourself. See this example. It builds a query that uses the maxResults value in this method.


I had a look at the code for implementation of sorting/pagination using custom data sources. It looks to me that the stated functions are performed on single entities.

Mine is a native query containing inner joins with more than 7 tables (result set data is to retrieved from these tables). The search criteria is passed through various datasource objects which are accessible only to screen controllers.

Please suggest an appropriate way to perform sorting/pagination on the result set from the parameterized query.


You are not right. This sample generates a proper query with ordering. You can generate your own for as many joins as you need. Just, write a proper logic forming a query.


I don’t see any issue with the query. The only point I can make here is that besides being a native query, it is part of the service bean class than the custom data source class. The reason for it being in service class is it is parameterized (criteria parameter values are passed from the UI and they flow from controller to service).
Additionally, I’m not sure of how to pass in parameters to the init() method of the CustomValueCollectionDatasource.

Sorting is working but not pagination.
Technically I reached a point where I need a way to pass the data source parameter “firstResult” between page traversals.

On a side note: Pagination at data source, as you suggested, would lead to trip to database for every page.

Please have a look to the sample once again. You will see that it uses firstResult and maxResults values, which can be set in your datasource, using setters. Use them to implement pagination and note that if you are using table UI component with linked data source it will propagate these values automatically.