Tuesday, July 20, 2010

Editor Grid and checkboxSelectionModel

I experienced that the check box selection model and the editor grid does not go along well if we are clicking on the row rather than only the check box. The problem is that the row gets selected and deselected when the editable cells are changed.

I needed to enable the select only when we click the first 2 columns and just editable on the rest.

A solution is to override handleMouseDown

  1: @Override
  2: protected void handleMouseDown(GridEvent e) {
  3: 	if (checkBoxOnly || checkBoxSynchronized) {
  4:         	if (e.getColIndex() < 3 && e.getEvent().getButton() == NativeEvent.BUTTON_LEFT) { 
  6: 	        	M m = listStore.getAt(e.getRowIndex());
  7: 			if (m != null) {
  8: 		        	if (isSelected(m)) {
  9: 					doDeselect(Arrays.asList(m), false);
 10: 				} else {
 11: 					doSelect(Arrays.asList(m), true, false);
 12: 				}
 13: 			}
 14: 		}
 15: 	} else {
 16: 	       super.handleMouseDown(e);
 17: 	}
 18: }

No comments: