lundi 9 décembre 2019

Check/Uncheck CheckboxCell, onclick of a row - GWT

I have a cell table with the first column as checkboxes. My checkboxes have to be checked or unchecked when there is any single click event on the entire row. This is the following code for creating a MultiSelectionModel, creating CheckboxCell and creating a column for cell table.

MultiSelectionModel<Object> selectionModel = new MultiSelectionModel<>();
    table.setSelectionModel(selectionModel);

    CheckboxCell selectedCell = new CheckboxCell();
    Column<Object,Boolean> selectedCol = new Column<Object, Boolean>(selectedCell){
        @Override
        public Boolean getValue(Object object) {
            return object.isSelected();
        }
    };
    table.addColumn(selectedCol);


    //Single Click Event to Enable/Disable checkbox.
    table.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            Set<Object> selectedItems = selectionModel.getSelectedSet();

            for (Object s : selectedItems) {
                Window.alert(String.valueOf(s));
                selectionModel.setSelected(s, true);
            }
        }
    }, ClickEvent.getType());

I tried to mark a row as checked using "selectionModel.setSelected(s, true)". But it isn’t working, when I clicked on row, the corresponding checkbox is not being checked.

My question is how do I enable/disable checkboxes onclick of an entire row. Is my approach correct. Or Is there any other way to perform this action in GWT.




Aucun commentaire:

Enregistrer un commentaire