Problem:
We have a ListGrid that is initialised with data from an RPC call (ListGrid update method 1) - we use _listGrid.getDataSource().setCacheData(<record[]>) and _listGrid.setData(<record[]>) to initialise the data from the RPC call.
The ListGrid is then updated throughout the day from JSON messages pushed over a Socket (ListGrid update method 2). Our app converts the JSON into TargetRecord <extends ListGridRecord> objects and adds them to the client only datastore using the call: _listGrid.getDataSource().addData(newRecord);.
We then call _listGrid.filterData() (to pull the newly added data into the ListGrid) and _listGrid.resort() (this restores the treestate of open folders prior to the filterData() call).
If we receive JSON that matches the record selected in the ListGrid, that record is updated in the grid.
This works ok when we have selected a ListGrid record that was loaded from RPC data (Method 1 above).
However, if we select a record that was added using Method 2, we start running into Class Cast errors with line 2 below:
Code:
final RecordList recordList = _listGrid.getDataAsRecordList();
final TargetRecord oldRecord = (TargetRecord) recordList.find(Constants.FIELD_PK, target.getTgtID());
We have worked around this using:
Code:
final Record record = recordList.find(Constants.FIELD_PK, target.getTgtID());
TargetRecord oldRecord = new TargetRecord(record.getAttributeAsString(Constants.FIELD_PK), record.getAttributeAsString(Constants.FIELD_INSTRUMENT), etc...);
But now the resort() does not restore the tree state so we are trying to handle this ourselves by using:
Code:
final ListGridRecord selectedRecord = _listGrid.getSelectedRecord();
...
if (selectedRecord != null) {
_listGrid.selectRecord(selectedRecord);
final TreeNode parentNode = _listGrid.getGroupTree().getParent(new TreeNode(selectedRecord.getJsObj()));
// open the node hierarchy of selected record
_listGrid.getGroupTree().openFolder(parentNode);
}
However, despite the fact that selectedRecord is not null, the record does not select in the listGrid, nor does the parent folder open.
1. SmartGWT version: SmartClient Version: v9.0p_2013-10-28/LGPL Development Only (built 2013-10-28)
2. Any browser
3. server-side problem: N/A
4. problem processing a server response: N/A
5. JavaScript error, the stack trace logged in the Developer Console (see FAQ)
6. sample code: can be provided.
How do I get the non-null selected record object to reselect in the grid so I can open the node hierarchy of folders?