I would like to create some different views of my data on the client side. To do this, I have created a client-only DataSource. The DataSource is populated with values from a server DataSource.
My question: can I bind my client-only DataSource to the server DataSource so that I can update my client-only DataSource when the server DataSource changes?
I realize another way for me to achieve this is to do this server side. I would rather do it on the client side, but will resort to doing it on the server if necessary.
As a concrete example, say what I want to do is transpose (ie, rotate) a table. This is not what I want to do, but similar.
It appears not, since a DataSource does not really ‘exist’ as an instance in the client code. I discovered I can do something similar by binding one ListGrid.ResultList to another component with the DataChanged/Arrived events.
Here’s a way of doing that.
final ListGrid hiddenGrid = new ListGrid();
hiddenGrid.setDataSource(serverDS);
hiddenGrid.fetchData(null,new DSCallback() {
@Override
public void execute(DSResponse response, Object rawData, DSRequest request) {
hiddenGrid.getRecordList().addDataChangedHandler(
new DataChangedHandler() {
@Override
public void onDataChanged(DataChangedEvent event) {
updateClientDS(hiddenGrid.getRecordList());
}
});
}
});
hiddenGrid.setVisible(false);
addMember(hiddenGrid);
And this works just as hoped.
Any comments or cause for concern? Otherwise, I hope this is useful for anyone else who is trying to do DataSource transforms on the client side.