简体   繁体   中英

GWT CellTable: Selecting one checkbox selects every checkbox/row in the table

I have a very basic CellTable in GWT right now and use a majority of the code shown here .

However when I toggle a checkbox, every single row gets highlighted.

Preview: gfycat

I did try so far:

  • Multi-/SingleSelectionMode: (I only want to get one row, so I would prefer SingleSelectionMode)

  • CheckBoxCell(true, true): -> This is exactly how I want the CellTable to look, however with these parameters I can't get an object with "getSelectedObject()". Other variations of the parameters(false,false/true, false) also didn't seem to work

    CellTable<Article> ArticleCt = new CellTable<Article>(KEY_PROVIDER); 

    ListHandler<Article> sortHandler = new ListHandler<Article>(Articles);
    ArticleCt.addColumnSortHandler(sortHandler);

    final MultiSelectionModel<Article> selectionModel1 = new MultiSelectionModel<Article>(KEY_PROVIDER);

    ArticleCt.setSelectionModel(selectionModel1, DefaultSelectionEventManager.<Article> createCheckboxManager());

    Column<Article, Boolean> checkColumn = new Column<Article, Boolean>(
                  new CheckboxCell(true, false)) {

      public Boolean getValue(Article object) {

      return selectionModel1.isSelected(object);
    }
    };

I want to have only the row with the checked checkbox selected so I can fetch the peticular row/object with selectionMode.getSelectedObject() or selectionMode.getSelectedSet() .

However every single row gets highlighted.

Your key provider, KEY_PROVIDER in the question above, must provide unique and consistent keys per row. For example, each row might have an "ID" field.

If more than one row shares a key, then selecting one seems to be the same to the selection model as selecting both. If a row's key is not consistent, then when a row is selected, it can't be queried later since its key changed.

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