1. v9.1p_2014-07-03/Pro"
2. Any browser
The selected row(s) in a databound listGrid get 'unselected' when the datasource has any record updated or added.
This was not the case in earlier versions. Is this intended?
Code below builds a datasource, listGrid and 2 buttons (load and update). Click the load button to load sample data, fetchData call back will select the 2nd row, then click the update button which will update the 2nd row in the datasource. This caused the selected row in the grid to be unselected.
Thanks
2. Any browser
The selected row(s) in a databound listGrid get 'unselected' when the datasource has any record updated or added.
This was not the case in earlier versions. Is this intended?
Code below builds a datasource, listGrid and 2 buttons (load and update). Click the load button to load sample data, fetchData call back will select the 2nd row, then click the update button which will update the 2nd row in the datasource. This caused the selected row in the grid to be unselected.
Code:
public class Test implements EntryPoint { ListGrid grid; DataSource dataSource; @Override public void onModuleLoad() { VLayout appLayout = new VLayout(); appLayout.setWidth100(); appLayout.setHeight100(); buildDataSource(); buildGrid(); grid.setDataSource(dataSource, grid.getAllFields()); IButton btnLoad = new IButton("Load"); btnLoad.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { loadData(); } }); IButton btnUpdate = new IButton("Update"); btnUpdate.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { updateData(); } }); appLayout.addMembers(btnLoad, btnUpdate, grid); appLayout.draw(); } protected void updateData() { //update the 2nd record Record rec = new Record(); rec = new ListGridRecord(); rec.setAttribute("fldId", 2); rec.setAttribute("fld1", "val 222"); rec.setAttribute("fld2", 200); rec.setAttribute("fld3", new Date()); dataSource.updateData(rec); //causes listgrid to unselect selected records //v9.0p_2013-10-17 - works //v9.1p_2014-07-03 - broken } private void loadData() { ListGridRecord[] cacheData = new ListGridRecord[3]; cacheData[0] = new ListGridRecord(); cacheData[0].setAttribute("fldId", 1); cacheData[0].setAttribute("fld1", "val 1"); cacheData[0].setAttribute("fld2", 10); cacheData[0].setAttribute("fld3", new Date()); cacheData[1] = new ListGridRecord(); cacheData[1].setAttribute("fldId", 2); cacheData[1].setAttribute("fld1", "val 2"); cacheData[1].setAttribute("fld2", 20); cacheData[1].setAttribute("fld3", new Date()); cacheData[2] = new ListGridRecord(); cacheData[2].setAttribute("fldId", 3); cacheData[2].setAttribute("fld1", "val 3"); cacheData[2].setAttribute("fld2", 30); cacheData[2].setAttribute("fld3", new Date()); dataSource.setCacheData(cacheData); grid.setData(new ListGridRecord[] {}); //force the fetchData to execute it's callback grid.fetchData(null, new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { //select the 2nd record Record[] dataRecords = new Record[1]; dataRecords[0] = dsResponse.getDataAsRecordList().get(1); grid.selectRecords(dataRecords); } }); } private void buildGrid() { grid = new ListGrid(); grid.setAutoDraw(false); grid.setShowAllRecords(true); grid.setSelectionType(SelectionStyle.SINGLE); grid.setCanSort(true); grid.setUseAllDataSourceFields(false); grid.setWidth100(); grid.setHeight100(); ListGridField gfld1 = new ListGridField("fld1", "Field 1"); ListGridField gfld2 = new ListGridField("fld2", "Field 2"); ListGridField gfld3 = new ListGridField("fld3", "Field 3"); grid.setFields(gfld1, gfld2, gfld3); } private void buildDataSource() { dataSource = new DataSource(); dataSource.setClientOnly(true); dataSource.setDataFormat(DSDataFormat.JSON); DataSourceField fldId = new DataSourceField("fldId", FieldType.INTEGER); fldId.setPrimaryKey(true); DataSourceField fld1 = new DataSourceField("fld1", FieldType.TEXT); DataSourceField fld2 = new DataSourceField("fld2", FieldType.INTEGER); DataSourceField fld3 = new DataSourceField("fld3", FieldType.DATE); dataSource.setFields(fldId, fld1, fld2, fld3); } }
Comment