How to get the value of a cell in a table of cells using GWT

am using GWT 2.4, Hibernate and MysQL I created a table of cells, when I click on a cell, I want to display data / value in that specific cell

Thank you in advance

+3


source to share


2 answers


Use DataProvider

and SingleSelectionModel

to you cellTable

:

private final ListDataProvider<SomeClass> dataProvider = new ListDataProvider<SomeClass>();

private final SingleSelectionModel<SomeClass> selectionModel = new SingleSelectionModel<SomeClass>();
//then
table.setSelectionModel(selectionModel);    
dataProvider.addDataDisplay(table);  

      



Here's how you can get information about the selected objects:

        showDataValueOfCellBtn.addClickHandler(new ClickHandler() {     
        @Override
        public void onClick(ClickEvent event) {
            SomeClass selected = selectionModel.getSelectedObject();
            Window.alert (selected.getValue());
        }
    });  

      

0


source


@override
public Widget onInitialize(){

    CellTable grid = new CellTable<Bean>();
    grid.setWidth("100%",true);

    setColumns(grid);
}

private void setColumns(CellTable grid){

     Column<Bean, String> firstNameColumn = new Column<Bean, String>(
        new EditTextCell()) {
      @Override
      public String getValue(Bean object) {
        return object.getFirstName();
      }
    };
    firstNameColumn.setSortable(true);
    grid.addColumn(firstNameColumn, "First Name");

    Column<Bean, String> imageColumn = new Column<Bean, String>(
        new ClikableTextCell()) {
      @Override
      public String getValue(Bean object) {
        return "clickhere";
      }
    };
    imageColumn.setSortable(true);
    grid.addColumn(imageColumn, "Add Information");
    firstNameColumn.setFieldUpdater(new FieldUpdater<Bean, String>() {
      public void update(int index, Bean object, String value) {
        Window.alert("You clicked " + object.getFullName());
      }
    });
    cellTable.setColumnWidth(firstNameColumn, 20, Unit.PCT);
}

      



0


source







All Articles