Leverage filter component on custom data sources?

Hi all,

I implemented a custom data source because the columns of this data source map to rows in a table. The rows doesn’t change much but each time new rows are added, I update the entity, the data source definition and the lookup service to support newly added columns.

The direct problem I’m facing now is that such custom data source (of a custom entity which is not a table, with predefined columns) cannot be used together with the filter component, because it doesn’t have a query in its definition.

My question is:

  • Is there a better way to define the data source than custom implementation with a Java class?
  • If not, is there a way to use the filter component with this custom data source?

Thanks!

Hi Max,

In fact, the generic filter component can be used with custom datasources. For example, the following implementation of a datasource works perfectly with the filter:


package com.company.cds.web.customer;

import com.company.cds.entity.Customer;
import com.haulmont.cuba.gui.data.impl.CustomGroupDatasource;

import java.util.Collection;
import java.util.Map;
import java.util.UUID;


public class MyCustomersDatasource extends CustomGroupDatasource<Customer, UUID> {

    @Override
    protected Collection<Customer> getEntities(Map<String, Object> params) {
        return dataSupplier.loadList(getCompiledLoadContext());
    }
} 

The CollectionDatasourceImpl#getCompiledLoadContext method creates LoadContext based on the query and current filter.

I’m not sure it is applicable to your case, but in theory you could analyze the content of the LoadContext and load your data accordingly.

1 Like

Hi Konstantin,

I am trying to achieve the same as Max mentioned. So far I have implemented a class which extends custom collection datasource and populate a grid by calling service bean. But the question is to apply filter on the records by any component. In general, this works by applying valueChangeListener to the component but it does not work with custom datasource.

Looking for directions.

Regards,
Sanchit