checkboxsmartgwtlistgridischecked

Smartgwt: How to get checkbox value on a listgrid?


I've a listener on cellClick, I get the selected Record but I can't find a way to understand if this record is checked

Method ListGrid.isSelected(ListGridRecord) returns true if row is selected, not if is checked

My Code:

listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
            listGrid.addCellClickHandler(new CellClickHandler() {

                @Override
                public void onCellClick(CellClickEvent event) {

                    if(event.getColNum() == 0 && idMenu != null){
                        boolean isChecked = event.getRecord().???;

                        if(isChecked)
                            ....
                        else
                                                    ....
        }

I've tried also with event.getRecord().getAttributeAsBoolean("_checkField") with no success...


Solution

  • I found a simply solution...

    My task is solved using a special boolean field in the DataSource named, for example, "checked" In ListGrid I've a field "checked", and with a RecordClickHandler I can manage check or uncheck event.

    DataSource code:

    DataSourceBooleanField checkField = new DataSourceBooleanField("checked");

    ListGrid code:

    listGrid.addRecordClickHandler(new RecordClickHandler() {

    @Override
    public void onRecordClick(RecordClickEvent event) {
                    Record rec = event.getRecord();
    
                    boolean checked = rec.getAttributeAsBoolean("checked");
    
                    if(checked){
                      ...   
                    }else{
                       ...
                    }
    
                    rec.setAttribute("checked", !checked);
    
                    catPgrid.saveAllEdits();
                    catPgrid.refreshFields();
                }
            });
    
    
            ListGridField checkField = new ListGridField("checked", "Sel");