Hi, is it possible to replace the select all checkbox with a custom one?
Or is it possible to intercept the select all click ?
I need to evaluate the number of record and ask a confirm in case the number of records is greater than 500
Thanks
Hi, is it possible to replace the select all checkbox with a custom one?
Or is it possible to intercept the select all click ?
I need to evaluate the number of record and ask a confirm in case the number of records is greater than 500
Thanks
I assume the selection and the processing are two separate user actions.
If so, why not let the processing action check the number of rows?
Thanks Vik,
at the moment i have no control on the standard checkbox component, as the user click on it the selection starts.
what i need is to intercept the select all event and evaluate if ask to the user if process the selection or not
As i know the grid does not offer the select all event
One option might be to extend from AbstractGridMultiSelectionModel, and then override clientSelectAll to implement your custom check. To use the custom selection model you’ll also need to extend Grid to get access to the protected setSelectionModel method.
I think we’re talking past one another.
What I was asking was if you could do the test later:
var grid = ...
var processSelectedRows = new Button("Process Selected Rows", e -> {
if(grid.getSelectedItems().size() >= 500) {
var dialog = new ConfirmDialog();
dialog.addConfirmListener(e -> doAction());
dialog.open();
}
else {
doAction();
}
});
Sorry, I have to check it before selecting because there are about a hundred thousand records and I want to ask the user before selecting that it is a burdensome task.
Hi, seems that overriding clientSelectAll is the way, thanks
when the user press cancel, the first time the check box select all is unset, the other times, the check box remain setted, any hint?
@Override
protected void clientSelectAll() {
// Esempio di check custom:
// - prendo tutti gli item visibili dal DataProvider
// - se superano una soglia, blocco il select-all
// - altrimenti seleziono solo quelli “ammissibili” (altro check esempio)
int size = getGrid().getDataProvider().size(new com.vaadin.flow.data.provider.Query<>());
if (size > maxSelectAll) {
ConfirmDialog dialog = new ConfirmDialog();
dialog.setHeader("Selection");
dialog.setText(
"To many elements (" + size + ") do you want to continue?");
dialog.setCancelable(true);
dialog.addCancelListener(event ->{
super.clientDeselectAll();
deselectAll();
return;
} );
dialog.setConfirmText("Continue");
dialog.addConfirmListener(event -> {
super.clientSelectAll();
});
dialog.open();
}
}
I’d assume the problem is that this call in clientDeselectAll will not have any effect from the second time its called:
selectionColumn.setSelectAllCheckboxState(false);
The reason is that Flow will not detect a state change, as the property value was already false because your override to clientSelectAll prevents it from changing to true. Unfortunately toggling the property in the same request will also not work - I think Flow only syncs to the client what has effectively changed at the end of the request. So I’d guess the only option is to force an update to the client with Javascript:
dialog.addConfirmListener(event -> {
super.clientSelectAll();
getSelectionColumn().getElement().executeJs("this.selectAll = false");
});