Adding clickHandler to row in CellTable in GWT?

后端 未结 2 1187
生来不讨喜
生来不讨喜 2020-12-05 11:55

I have created a basic CellTable and filled it with some data. Now I want to add a clickHandler to each row but I\'m not sure how to do this. I\'ve created a clickEvent for

2条回答
  •  既然无缘
    2020-12-05 12:02

    Another way to have a cell selected can be made using a NoSelectionModel and add it to the table:

    //EDIT: this is a field, not a local variable
    TheCellObject clickedObject; //the object selected by selectionModel
    
    final NoSelectionModel selectionModel = new NoSelectionModel();
    
        selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
    
                    @Override
                    public void onSelectionChange(SelectionChangeEvent event) {
                        clickedObject = selectionModel.getLastSelectedObject();
                    }
                });
    cellTable.setSelectionModel(selectionModel); //add selection model to your celltable
    

提交回复
热议问题