Mohita Gakhar
Mohita Gakhar

Reputation: 23

How to add a column of checkbox in a grid where only one can be selected across all rows?

I have an Inline Editable grid with a column for checkboxes. How do I make sure that only one of those checkboxes in all the rows is checked? Whenever the user checks one checkbox, the previously selected checkbox if any should get unselected by default.

Upvotes: 0

Views: 653

Answers (1)

El Hoss
El Hoss

Reputation: 3832

Assuming that you are talking about Sencha GXT, the following code will work:

Create a IdentifyValueProvider and a SelectionModel:

IdentityValueProvider<M> identity = new IdentityValueProvider<M>();
final CheckBoxSelectionModel<M> selectionModel = new CheckBoxSelectionModel<M>(identity);

Add the checkbox column to your grid with:

columns.add(selectionModel.getColumn());

And add the SelectionModel to the grid:

grid.setSelectionModel(selectionModel);

Setting the selection mode to SINGLE will solve your requirement:

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

Hope that helps.

Upvotes: 1

Related Questions