Hello, please correct me if I’m wrong but it seems there is a bug with the Grid and multi-select. When you enable multi-select, and display the “Select All” checkbox, and then select the checkbox to “Select All”, it selects everything as expected. However, if you then de-select one item, it does not update the selected items list in the code. It still has all the items in the grid as part of the selected items list in the code. No events fire either…
Hi Tatu, I’m using the latest version. I have verified the sampler as well, but I can’t see the full code in there on when the update button is clicked. We are just checking the selectedItmens method in the multi selection model, and it stays the same.
Can we possibly get the full snippet of code of the sampler?
Hello Tatu. Another issue with the grid. If I click “select all” and begin to scroll down, I see that some records are not selected. And when I scroll back up, some that were originally selected are not selected anymore. This is something I wouldnt be able to see through the sampler, as my datatset is over 2000 records in this scenario. I also want to mention that data is being pulled from a database using the Dataprovider.
As Tatu noted, the grid multi-select seems to be working as expected. This can be verified using the following snippet (tested on Vaadin release 8.10.1):
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
List<Issue> issueList = new ArrayList<>();
issueList.add(new Issue("Issue #1", "new"));
issueList.add(new Issue("Issue #2", "new"));
issueList.add(new Issue("Issue #3", "new"));
Grid<Issue> grid = new Grid<>(Issue.class);
grid.setItems(issueList);
grid.setSelectionMode(SelectionMode.MULTI);
Label selected = new Label();
selected.setCaption("Selected issues: ");
grid.addSelectionListener(e -> selected.setValue(e.getAllSelectedItems().toString()));
final VerticalLayout layout = new VerticalLayout();
layout.addComponents(grid, selected);
setContent(layout);
}
/**
* Example object.
*/
public static class Issue {
private String issueName;
private String status;
public Issue() {
}
public Issue(String issueName, String status) {
this.issueName = issueName;
this.status = status;
}
public String getIssueName() {
return issueName;
}
public void setIssueName(String issueName) {
this.issueName = issueName;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public String toString() {
return issueName;
}
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
Shavon Tate:
Hello Tatu. Another issue with the grid. If I click “select all” and begin to scroll down, I see that some records are not selected. And when I scroll back up, some that were originally selected are not selected anymore. This is something I wouldnt be able to see through the sampler, as my datatset is over 2000 records in this scenario. I also want to mention that data is being pulled from a database using the Dataprovider.
If you are not using in memory data provider by default the select all check box should not be there at all. See JavaDoc of grid.asMultiSelect().setSelectAllCheckBoxVisibility(visibility);
Sets the select all checkbox visibility mode.
The default value is SelectAllCheckBoxVisibility.DEFAULT, which means that the checkbox is only visible if the grid's data provider is in- memory.
Also see the warning of grid.asMultiSelect().setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.VISIBLE);
Shows the select all checkbox, regardless of data provider used.
For a lazy data provider, selecting all will result in to all rows being fetched from backend to application memory!
This however may depend on how you have implemented your data privider.
Not sure if that’s the cause of your issue, but one thing I noticed in your earlier snippet is that in GetDataQuery() you select based on all records in the backend whereas in your GetDataCountQuery() you count the distinct records. This is not the right usage as I understand it. As described in the docs on dataprovider:
The results of the first and second callback must be symmetric so that fetching all available items using the first callback returns the number of items indicated by the second callback. Thus if you impose any restrictions on e.g. a database query in the first callback, you must also add the same restrictions for the second callback.
Indeed, actually as I note in my edited response (sorry about the confusion) I think the issue might be that in GetDataQuery() you select based on all records in the backend whereas in your GetDataCountQuery() you count the distinct records