Toggle all Checkboxes in a Grid Column on/off at once

Hi!
Please note that I am a student. I need some help because I’m stuck.
I have completed the tutorial, and I would like to further develop the “7. Creating UI from Scratch” chapter.

How can I develop to toggle all Checkboxes in a Grid Column on/off at once?
First I have made a Checkbox in the header. But what’s the next step? How can I access the Checkboxes in the rows?

Please note that I want to continue the 7th lesson and not to use: DataGrid.setSelectionMode(Grid.SelectionMode.MULTI);

Thank you in advance for your help.

public void onInit(final InitEvent event) {
    Checkbox headerCheckbox = uiComponents.create(Checkbox.class);
    Grid.Column<UserStep> completedColumn = stepsDataGrid.addComponentColumn(userStep -> {
        . . . ;
        }).setHeader( headerCheckbox )
          .setKey("checkbox0");
    . . .
    headerCheckbox.addClickListener( e -> {
        Grid.Column<UserStep> checkBoxColumn = stepsDataGrid.getColumnByKey("checkbox0");
         //TODO: ???
    });

image

Hi!

Please note that I want to continue the 7th lesson and not to use: DataGrid.setSelectionMode(Grid.SelectionMode.MULTI);

What is the motivation for refusing a ready-made solution?
Does this have any practical meaning? Or some business task?

Regards,
Dmitriy

Hi,
the advantage of this solution is that the Select function remains, which can be used for other services as well.
For example, if I click on a row, a modal window will pop up for editing the record.
Another example: on click, a view can pop up with detailed information, allowing for the use of a smaller and easier-to-understand grid, which is a more user-friendly solution.
Regards,
Aladár

There are ready-made solutions for all this, look here:

It still unclear why the standard multiselect logic needs to be rewritten.

Rewriting standard logic is a bad idea for several reasons:

  1. It is impossible to predict where it might be used. For example, standard logic can throw events that can be processed on the client side.
  2. Adding your own functionality to the client part entails a contract for its support in the future too. You will have to track updates and check each time to see if your logic breaks anything.
  3. It’s easy to make mistakes during your own implementation.
  4. etc.

Please note, that I am not talking about adding existing functionality in special cases.
What I mean is that implementing something that already exists is not recommended.

At the very least, it is not recommended to implement your own “multiple selection” when there is a standard one.

Try to implement your functionality using the provided API (I have attached the links above).

Regards,
Dmitriy

Thank you for the answer, and I completely agree that it is unnecessary to redevelop what already exists. And in any case, the standard solution should be used.

Actually, I didn’t want anything else but to continue your 7th lesson and put the accelerator button on the header. I haven’t figured out how to do that. by any standard procedure. that’s all.
I can’t put a business case next to it, so I can let it go.
Regards,
Aladár