简体   繁体   中英

how to add a clickHandler on a subRow of celltable in GWT

I am using Custom Data Grid from GWT showcase example .. http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCustomDataGrid

Every thing is working fine ..I have sub Rows inside my rows in the cell table ..

I have anchor cell.. which are in the main row and in the sub row ..

the ClickHandler for the main row is working but not in the sub row ..

this is my code for that cell

// ViewDetail.
td = row.startTD();
td.className(cellStyles);
td.style().trustedColor("blue");
td.style().cursor(Cursor.POINTER);

if (isNetworkRow) {
  //td.text("subRowsAnchor");
} else {

}
renderCell(td, createContext(19), viewDetailsColumn, rowValue);

I am rendering the cell in both cases , either its a row or sub row so i can see the anchor and its clickHandler also works ..

Is there any way i can differentiate that which anchor is been clicked ,, main rows or sub row's.

I just tried to make a small work around . ie changing the name of the anchor text if its a sub row .. as u can c in my code .. td.text ..

but then get the error on renderCell...

Attributes cannot be added after appending HTML or adding a child element.

Any idea , what could be solution...

thanks

To distinguish between which row has been clicked (according to the showcase sample, but should be the same in general), simply rely on which row has been selected (provided that you haven't overridden/disabled the selection handling).

Set up a FieldUpdater to the column (that renders itself using your anchor cell) and check for the subrow selection using getKeyboardSelectedSubRow() . Something like:

yourColumn.setFieldUpdater(new FieldUpdater<T, String>() {
  public void update(int index, T object, String value) {
    if (yourGrid.getKeyboardSelectedRow() != -1 ) {
      if (yourGrid.getKeyboardSelectedSubRow() > 0) {
        // Subrow selected.
      } else {
        // Main row selected.
      }
    }
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM