Following the Grid Filtering example, I made a Grid where it loads the data and filters correctly, however when I update the list and the data in the Grid, the filters stop working, does anyone know what I am doing wrong?
private Grid<CampaignScheduledDTO> createCampaignGrid() {
log.debug("Loading. . . . createCampaignGrid");
campaignScheduledGrid = new Grid<>(CampaignScheduledDTO.class, false);
campaignScheduledGrid.setWidth("100%");
campaignScheduledGrid.getStyle().set("flex-grow", "0");
List<CampaignScheduledDTO> scheduleByDate = loadCampaignScheduleService(actualLine);
Grid.Column<CampaignScheduledDTO> activeColumn = campaignScheduledGrid.addComponentColumn(CampaignScheduledDTO -> createStatusIcon(CampaignScheduledDTO.getActive()));
Grid.Column<CampaignScheduledDTO> stretchlineColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getStretchlineFk).setSortable(true);
Grid.Column<CampaignScheduledDTO> nameColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getName).setWidth("230px").setFlexGrow(0).setSortable(true);
Grid.Column<CampaignScheduledDTO> productFkColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getProductFk).setSortable(true);
Grid.Column<CampaignScheduledDTO> cOutputColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getCOutput).setSortable(true);
Grid.Column<CampaignScheduledDTO> speedColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getSpeed).setSortable(true);
Grid.Column<CampaignScheduledDTO> tonnageColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getTonnage).setSortable(true);
Grid.Column<CampaignScheduledDTO> mrschedCountColumn = campaignScheduledGrid.addColumn(CampaignScheduledDTO::getMrschedCount).setSortable(true);
campaignScheduledDataView = campaignScheduledGrid.setItems(scheduleByDate);
CampaignScheduledFilter campaignScheduledFilter = new CampaignScheduledFilter(campaignScheduledDataView);
campaignScheduledGrid.getHeaderRows().clear();
HeaderRow headerRow = campaignScheduledGrid.appendHeaderRow();
headerRow.getCell(activeColumn).setComponent(
createFilterHeader(" ", campaignScheduledFilter::setActive));
headerRow.getCell(stretchlineColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.line"), campaignScheduledFilter::setStretchlineFk));
headerRow.getCell(nameColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.name"), campaignScheduledFilter::setName));
headerRow.getCell(productFkColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.product"), campaignScheduledFilter::setProductFk));
headerRow.getCell(cOutputColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.output"), campaignScheduledFilter::setCOutput));
headerRow.getCell(speedColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.speed"), campaignScheduledFilter::setSpeed));
headerRow.getCell(tonnageColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.tonnage"), campaignScheduledFilter::setTonnage));
headerRow.getCell(mrschedCountColumn).setComponent(
createFilterHeader(getTranslation("hexagon.mcr.campaign.grid.column.count"), campaignScheduledFilter::setMrschedCount));
campaignScheduledGrid.addSelectionListener(selection -> {
Optional<CampaignScheduledDTO> optionalCampaign = selection.getFirstSelectedItem();
if (optionalCampaign.isPresent()) {
campaignSelected = optionalCampaign.get().getName();
updateMillrollScheduledData(campaignSelected);
log.debug("campaignScheduledGrid -> campaignSelected: {}", campaignSelected);
}
});
return campaignScheduledGrid;
}
private void updateCampaignScheduledGridData(String line) {
log.debug("Loading. . . . updateCampaignScheduledGridData");
log.trace("(Line -> {})", line);
List<CampaignScheduledDTO> scheduleByDate = loadCampaignScheduleService(line);
campaignScheduledDataView = campaignScheduledGrid.setItems(scheduleByDate);
campaignScheduledGrid.getDataProvider().refreshAll();
}
As you can see the code is very similar to the example, the updateCampaignScheduledGridData method is executed by a Select, In the method from a service it loads the data and puts it in the DataView, the information is updated correctly in the grid, but the filters are no longer working.
What can I do? Thank you very much for your help