Hi,
Javadocs for com.smartgwt.client.widgets.grid.events.CellSelectionChangedEvent.cancel() say
but the selected style *is* applied on the cell after cancel.
repro on SNAPSHOT_v8.3d_2012-09-17/Pro and SNAPSHOT_v8.3d_2012-10-11/Pro.
This code will enable a button when cells in row 1 are selected, not when cells in row 0 are selected. When you click a cell in row 0, the button stays disabled (so the cancel() succeeded), but the cell's selected style itself is applied (NOK).
* I also notice some redraw problems when I click the "select row 40 button". When I hover over the row with the mouse, the selected style is applied.
* What I wanted to investigate is what happens when I hit CTRL+A. Then I guess only 1 event is thrown instead of one event for each cell. So I guess I can't cancel the selections for row 0 that way and must manually deselect them. Or is there a better way?
thanks,
Javadocs for com.smartgwt.client.widgets.grid.events.CellSelectionChangedEvent.cancel() say
Calling this method will prevent the GridRenderer styling from being updated to reflect the selection change.
repro on SNAPSHOT_v8.3d_2012-09-17/Pro and SNAPSHOT_v8.3d_2012-10-11/Pro.
This code will enable a button when cells in row 1 are selected, not when cells in row 0 are selected. When you click a cell in row 0, the button stays disabled (so the cancel() succeeded), but the cell's selected style itself is applied (NOK).
Code:
final ListGrid grid = new ListGrid(); grid.setWidth(200); grid.setHeight(100); String fieldName1 = "a"; String fieldName2 = "b"; ListGridField field1 = new ListGridField(fieldName1); ListGridField field2 = new ListGridField(fieldName2); grid.setFields(field1, field2); ListGridRecord [] records = new ListGridRecord[100]; for (int i=0; i<records.length; i++) { records[i] = new ListGridRecord(); records[i].setAttribute(fieldName1, "aha" + i); records[i].setAttribute(fieldName2, "oho" + i); } grid.setRecords(records); HLayout buttons = new HLayout(); IButton select = new IButton("select row 40"); select.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { grid.selectSingleRecord(40); grid.scrollToRow(40); } }); final IButton doSomething = new IButton("do something"); doSomething.setDisabled(true); buttons.setMembers(select, doSomething); grid.setCanEdit(false); grid.setShowRollOver(false); grid.setShowSelectedStyle(true); grid.setCanSelectCells(true); grid.setCanSelectAll(true); grid.addCellSelectionChangedHandler(new CellSelectionChangedHandler() { public void onCellSelectionChanged(CellSelectionChangedEvent event) { SC.logInfo("onCellSelectionChanged started"); int[][] ee = event.getCellList(); for (int i=0; i<ee.length; i++) { SC.logInfo("event for cell (" + ee[i][0]+","+ee[i][1]+")"); } for (int i=0; i<ee.length; i++) { if (ee[i][1] == 0) { // don't allow selections in the first column // CTRL+A sends 1 event event.cancel(); return; } } // enable/disable action button when there are valid cells selected CellSelection cellSelection = grid.getCellSelection(); doSomething.setDisabled(!cellSelection.anySelected()); } }); VLayout layout = new VLayout(); layout.setWidth100(); layout.setHeight(600); layout.setMembers(grid, buttons);
* What I wanted to investigate is what happens when I hit CTRL+A. Then I guess only 1 event is thrown instead of one event for each cell. So I guess I can't cancel the selections for row 0 that way and must manually deselect them. Or is there a better way?
thanks,
Comment