I have done filtering over lookup field selection but now I’m trying to filter data over optionsGroup item selection.
ex- If I select ‘item1’ the table should display all the values containing ‘item1’ and similarly, de-selection leads back to normal table.
Is it possible? I haven’t found any examples related to this.
You can use the selected value of your optionsGroup in the where-clause of the table’s row datasource:
<collectionDatasource id="filteredDs"
class="com.company.project.entity.MyTable"
view="myTable-view">
<query>
<![CDATA[select e from project$MyTable e
where e.item.id = :component$optionsGroup]]>
</query>
</collectionDatasource>
…and update the datasource using the optionsGroup valueChangeListener:
I was trying to use the similar approach but I got this error.
IllegalStateException: Query argument component_optionsGroup not found in the list of parameters provided during query execution.
IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter component_optionsGroup with expected type of class java.lang.String from query string select e from myproject$mytable e where e.type = :component_optionsGroup.
Hi Olga…
I am looking for the same requirement as stated above. i did everything as stated above… I am using groupdatasource. After the page load, the table doesnt populate any rows… And multiselect optionsGroup is also not selected. I’ve set the query correctly
the code i use is:
optionsGroup.setValue(taskManagersDs.getItems())
But when i check the optionGroup manually it loads the table according to the selection.
Initially, you can load all records with a simple datasource query: select e from pjw$TaskManager e, and add conditions only when the optionsGroup value is changed:
optionsStatus.addValueChangeListener(e -> {
taskManagersDs.setQuery("select e from pjw$TaskManager e where e.taskStatus in :component$optionsStatus and e.taskSeverity in :component$optionsSeverity");
taskManagersDs.refresh();
});
optionsSeverity.addValueChangeListener(e -> {
taskManagersDs.setQuery("select e from pjw$TaskManager e where e.taskStatus in :component$optionsStatus and e.taskSeverity in :component$optionsSeverity");
taskManagersDs.refresh();
});
Hi Olga thanks for the demo project. It works, but the optionGroup is not populated with values… Even i have included the following codes… But the checkboxes doesn’t get populated…
@Override
public void init(Map<String, Object> params) {
taskManagersDs.refresh();
optionsStatus.setValue(taskManagersDs.getItems());
optionsSeverity.setValue(taskManagersDs.getItems());
optionsStatus.addValueChangeListener(e -> {
taskManagersDs.setQuery("select e from demo$TaskManager e where e.taskStatus in :component$optionsStatus and e.taskSeverity in :component$optionsSeverity");
taskManagersDs.refresh();
});
optionsSeverity.addValueChangeListener(e -> {
taskManagersDs.setQuery("select e from demo$TaskManager e where e.taskStatus in :component$optionsStatus and e.taskSeverity in :component$optionsSeverity");
taskManagersDs.refresh();
});
}
I tried to put the setValue in ready method also, but it shows error...
Thanks....
The setValue() method of OptionsGroup takes a List of values, so try something like this:
<groupDatasource id="taskManagersDs"
class="com.company.demo.entity.TaskManager"
view="_local">
<query>
<![CDATA[select e from demo$TaskManager e where e.taskStatus in :component$optionsStatus and e.taskSeverity in :component$optionsSeverity]]>
</query>
</groupDatasource>