2

I've got a CellTable with a column rendered with a CheckboxCell. I want to check the boxes to select the rows.

The default behavior with CheckboxCell(false, false) is tantalizingly close to my goal - selecting a row checks the checkbox, and de-selecting a row unchecks the checkbox. However, if I click a checkbox, it unselects any already-selected rows. Even worse, when I uncheck a checkbox, the row is not deselected. Argh!

I'm looking at coding my own cell now (or messing with the SelectionModel?), but this seems like behavior Google might have been trying for. I've tried every permutation of values in the constructor, to no avail. Is there a simple override I can add to finally make my dream... a reality?

Riley Lark
  • 20,660
  • 15
  • 80
  • 128

1 Answers1

7

You know how you can search for 30 minutes, and then 20 seconds after you post your question you find your answer?

Well, it turns out that to unleash the power of the CheckboxCell, you need to pass a Handler that is equipped to deal with the complexities of the situation. Try

setSelectionModel(selectionModel, DefaultSelectionEventManager.<T> createCheckboxManager()); 

with your MultiSelectionModel selectionModel - the selectionModel itself is not enough!

Riley Lark
  • 20,660
  • 15
  • 80
  • 128
  • Was your CheckboxCell set to false, false or true, true? I implemented a select all checbox on the header datagrid that simply selects/unselects all checkboxes voa a jquery trigger function. However, the behavior of checboxes selected and unselected is not consistent when i set to any permutation of true, false, along with the MultiSelectionModel. – pri Jul 11 '12 at 05:41
  • I used false, false - which was very counter-intuitive to me. – Riley Lark Jul 11 '12 at 12:58
  • with (false, false) my "select all" checkboxes doesnt check/uncheck the last row, or sometimes a random row. (true, true) fixes this issue; however it doesnt retain row highlights after checking/unchecking checkboxes. – pri Jul 11 '12 at 14:17
  • Might be time to file a bug w/ GWT. FWIW: I implemented `select all` via the `selectionModel.setSelected` method instead of by "manually" clicking the checkboxes. With (false, false), this works like a charm. Good luck! – Riley Lark Jul 11 '12 at 16:27
  • You're right. I removed the jquery solution and added a custom Header with a CheckboxCell that performs the 'select all' functionality using a selectionModel. It works well with a (true,false) setting only. However, another issue I find now is that a row selection (not clicking a checkbox) doesn't return the selected value when selectionModel.getSelectedSet() is invoked. Only time when I get a value is a checkbox (or multiple checkboxes) is clicked. Would you know if there's a way to capture a row selection outside of checkbox selection? – pri Jul 11 '12 at 20:33
  • In other words, how do you add clickhandler to row (and get a reference to the current row object) without selection handler? – pri Jul 11 '12 at 21:06
  • Sounds like its own question :) – Riley Lark Jul 11 '12 at 21:51
  • Never mind, I got this working with the helo of: http://stackoverflow.com/questions/5792048/adding-clickhandler-to-row-in-celltable-in-gwt – pri Jul 11 '12 at 22:15