In my application i have added the serial numbers for the data in the database and auto incremented it. Now when I see it in my application it showing correctly as in order. But when I search them using filters the sno is populating as showing in the second image. i wanted the Sno from Serial num 1. Can you please suggest me how to refresh them. I have added the images in the below.
In the browser controller, create a listener that will fill in the attribute on each datasource refresh:
package com.company.sample.web.customer;
import com.company.sample.entity.Customer;
import com.haulmont.cuba.gui.components.AbstractLookup;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.GroupDatasource;
import com.haulmont.cuba.gui.data.impl.DatasourceImplementation;
import javax.inject.Inject;
import java.util.Map;
import java.util.UUID;
public class CustomerBrowse extends AbstractLookup {
@Inject
private GroupDatasource<Customer, UUID> customersDs;
@Override
public void init(Map<String, Object> params) {
// add listener on datasource content change
customersDs.addCollectionChangeListener(e -> {
// find page start
int counter = ((CollectionDatasource.SupportsPaging) customersDs).getFirstResult();
// for each entity in the datasource, set its sequence number
for (Customer customer : customersDs.getItems()) {
customer.setLineNum(++counter);
}
// make the datasource unmodified to prevent from asking to save changes on screen close
((DatasourceImplementation) customersDs).setModified(false);
});
}
}