Hi,
what is the recommended approach to augment criteria of a ListGrid FilterEditor?
Scenario:
A ListGrid and a FilterEditor to filter data; works OK.
Now, I want to introduce two new SelectItems (above the FilterEditor) showing data from a different DataSource.
The SelectItems should be used to determine the value of an artificial list grid field used to group the ListGrid.
This cannot be done on the client, so the current value of the SelectItems needs to be passed to the server.
I thought about using criteria for this and created two additional SelectItems in a filterForm above the ListGrid.
Now, what is the most suitable way to incorporate the SelectItems's information into the ListGrid's criteria?
So far I tried to add a FilterEditorSubmitHandler like this:
This works but accumulates the criteria of the criteriaFromSelectors if the filtering is done multiple times, i.e. event.getCriteria() next time already contains criteriaFromSelectors criteria from previous calls (is there a simple way to get rid of them?).
I also tried a whole battery of different approches (e.g. combining listGrid.getFilterEditorCriteria() and criteriaFromSelectors into a new criteria object and then doing a fetch(combinedCriteria)) but so far, each of them had at least one flaw. Before getting deeper into this, I'd like to know whether I have overlooked something obvious...
Thanks
fatzopilot
what is the recommended approach to augment criteria of a ListGrid FilterEditor?
Scenario:
A ListGrid and a FilterEditor to filter data; works OK.
Now, I want to introduce two new SelectItems (above the FilterEditor) showing data from a different DataSource.
The SelectItems should be used to determine the value of an artificial list grid field used to group the ListGrid.
This cannot be done on the client, so the current value of the SelectItems needs to be passed to the server.
I thought about using criteria for this and created two additional SelectItems in a filterForm above the ListGrid.
Now, what is the most suitable way to incorporate the SelectItems's information into the ListGrid's criteria?
So far I tried to add a FilterEditorSubmitHandler like this:
Code:
final SelectItem selector1 = new SelectItem("criteriaField1ID"); final SelectItem selector2 = new SelectItem("criteriaField2ID"); ... final DynamicForm filterForm = new DynamicForm(); //holds the two selectors ... filterForm.setFields(startAreaSelector, endAreaSelector); ... listGridInstance.addFilterEditorSubmitHandler(new FilterEditorSubmitHandler() { @Override public void onFilterEditorSubmit(FilterEditorSubmitEvent event) { if(selector1.getValue() != null && selector2.getValue() != null){ //just incorporate additional critieria if both fields are set Criteria criteriaFromSelectors = filterForm.getValuesAsCriteria(); final Criteria filterCriteriaFromGrid = event.getCriteria(); filterCriteriaFromGrid.asAdvancedCriteria().addCriteria(criteriaFromAreaSelectors); //needs to call asAdvancedCriteria(), otherwise, there is a JS error } };
I also tried a whole battery of different approches (e.g. combining listGrid.getFilterEditorCriteria() and criteriaFromSelectors into a new criteria object and then doing a fetch(combinedCriteria)) but so far, each of them had at least one flaw. Before getting deeper into this, I'd like to know whether I have overlooked something obvious...
Thanks
fatzopilot
Comment