Smartgwt: How to get checkbox value on a listgrid?

4.3k views Asked by At

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...

2

There are 2 answers

0
Zoiderberg On BEST ANSWER

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");
1
Nikhil Rane On

Maybe getSelectedRecords() method would help you!

Here is an API reference: http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/grid/ListGrid.html#getSelectedRecords()

Definitely this will provide all records which are selected (using checkbox) but there should be some values which you could use for identifying each record uniquely!