1. Tested with both 4.1p and 5.0p 2014-11-15
2. Tested with Chrome and Firefox
I want to select a record in the grid in the fetchData callback. Example below is selecting the first record in the grid.
When the grid contains more records than fit in the view port and the grids view port is positioned a few pages away from the record to be selected then the record is not selected.
In the example below, once the grid is loaded, scroll to the bottom of the grid and then click the load button. This will clear the grid data and reload a new set of data. The grid is refreshed but the first row is not selected. If the load button is clicked when grid is viewing one of the first few pages then the row is selected.
Seems to be a problem with the listGrid.selectRecords() and listGrid.selectRecord() when the grid view port is not near the row to be selected. This is only happening when selectRecord() is called from the fetchData callback. Works fine once the grid has been fully rendered.
Below is the simplest test case I code come up with.
Thanks
Robin
2. Tested with Chrome and Firefox
I want to select a record in the grid in the fetchData callback. Example below is selecting the first record in the grid.
When the grid contains more records than fit in the view port and the grids view port is positioned a few pages away from the record to be selected then the record is not selected.
In the example below, once the grid is loaded, scroll to the bottom of the grid and then click the load button. This will clear the grid data and reload a new set of data. The grid is refreshed but the first row is not selected. If the load button is clicked when grid is viewing one of the first few pages then the row is selected.
Seems to be a problem with the listGrid.selectRecords() and listGrid.selectRecord() when the grid view port is not near the row to be selected. This is only happening when selectRecord() is called from the fetchData callback. Works fine once the grid has been fully rendered.
Below is the simplest test case I code come up with.
Code:
package com.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.Version; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.DataSourceField; import com.smartgwt.client.data.Record; import com.smartgwt.client.types.DSDataFormat; import com.smartgwt.client.types.FieldType; import com.smartgwt.client.types.SelectionStyle; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VLayout; 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(); } }); appLayout.addMembers(btnLoad, grid); appLayout.draw(); loadData(); } private void loadData() { dataSource.setCacheData(getNewData()); 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 first record Record selectRecord = grid.getResultSet().first(); if (selectRecord != null) { Record[] selectRecords = new Record[1]; selectRecords[0] = selectRecord; grid.selectRecords(selectRecords); // grid.selectRecord(selectRecord); Record selRec = grid.getSelectedRecord(); if (selRec != null) { int selIndex = grid.getRecordIndex(selRec); if (selIndex != -1) { grid.scrollToRow(selIndex); } } } } }); } private ListGridRecord[] getNewData() { ListGridRecord[] cacheData = new ListGridRecord[60]; for (int i = 0; i < cacheData.length; i++) { cacheData[i] = createRecord(i); }; return cacheData; } private ListGridRecord createRecord(int i) { ListGridRecord record = new ListGridRecord(); record.setAttribute("fldId", i); record.setAttribute("fld1", "Text " + i); return record; } private void buildGrid() { grid = new ListGrid(); grid.setAutoDraw(false); grid.setSelectionType(SelectionStyle.SINGLE); grid.setCanSort(true); grid.setUseAllDataSourceFields(false); grid.setWidth100(); grid.setHeight100(); ListGridField gfld1 = new ListGridField("fld1", "Field 1"); grid.setFields(gfld1); } 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); dataSource.setFields(fldId, fld1); } }
Robin