Hi,
Maybe I’m overlooking something as this should be a simple task but just can’t make it work.
I have a ListGrid and i just want to be able to add initially a bunch of recs from an array or pulled via a DS from the server. Then I need to add, remove & update a record locally when certain events occur (i have a button now to do these; i’m not interested in sending the updates to the server or refreshing later from the server)
Test 1:
use a datasource (gwt style) to pull the initial content from the server; it has a primary key field declared and the grid shows nicely the content;
now try to add a new record (i’m interested only on the client to have it added) dataSource.addData(record); -> nothing happens, the grid doesn’t change listGrid.addData(record); -> nothing happens
-trying to remove an existing record via removeData has also no effect.
These are local only changes so no reason to pull again data from the server.
I also need to update only a specific row so i try:
int i= listGrid.getRecordIndex(rec); listGrid.updateData(rec); //the pk is the same listGrid.refreshRow(i);
I’ve noticed the index i is always -1 but if i list the listGrid.getRecords(), the pk is there.
Test 2
I also tried not to use a DS because i don’t think i really need it:
partsGrid.setData(recsArray);
The grid shows ok and i can add new recs but again I can’t update a row (returned index is -1 always)
Any advice please, what is the right way to do this?
Ok, i found the problem when i was using a DataSource. I was thinking that by doing locally grid.addData() the DS would not be implied. Turns out the DS processResponse must be called, when overriding the transformRequest(), even for these local operations.
Still, i was thinking to skip the DS and load the initial table via grid.setData(array). In this case i can add new recs but i can not an existing rec by:
int i=pGrid.getRecordIndex(rec); //always -1 !! pGrid.updateData(rec); pGrid.refreshRow(i);
The index of the existing rec is always -1.
So, should this work? What am I doing wrong?
Not sure why you’re getting -1 (you’d need to show more code), but a DataSource with clientOnly:true is the closest thing to your use case, and you don’t need to refreshRow because it happens automatically.
Thanks.
Right now i use a DS derived from the GwtRpcDataSource with setClientOnly(false) . However only the ‘fetch’ goes to server to pull the initial data. For ‘add’, ‘delete’, ‘update’, being local ops, i just call processResponse() and return (w/o this didnt work). This setup seems to work fine. Do you see anything stupid in doing this?
Now, i was thinking maybe it is possible to use a lighter solution in which I do NOT use a DS at all but just have the initial recs in an array (i’ll find a way to pull these from the server) and:
grid.setData(array);
and later, when needed: grid.updateData(aRec);
grid.addData(bRec);
grid.removeData(cRec);
However in this scenario (w/o using a DS) add/update/remove have no effect. Should this ‘array only’ approach work?
On last Q pls, I guess the records are looked up (for updates) only based on the primary key define field, right? Thanks!
If you want a clientOnlyDataSource, don’t subclass the GwtRpcDataSource, just subclass DataSource. Then you won’t have to write any code related to transformResponse or anything of the kind.
The best approach here is probably a GwtRpcDataSource that does the fetch, and a separate clientOnlyDataSource whose testData is populated from the result of calling fetchData on the GwtRpcDataSource.
Sounds like a good idea, thanks, i’ll go for it.
One last Q, I’ve noticed that if i do (the goal is to update a cell in the record for which i have the p key):
aGrid.updateData(record); // it takes over 1 sec to update one record (around 200 recs in grid);
Look for server calls. If you’ve misconfigured something the first call may still be trying to contact the server. That’s the only thing that could explain a non-negligible delay there.
For now i have a DS derived from GwtRpcDataSource. The ‘fetch’ grabs the initial data from server. Later, add/update/remove are done locally. For these local ops, in the DS i had to :
protected void executeAdd (final String requestId, final DSRequest request, final DSResponse response) { processResponse (requestId, response); //no server side processing, just do this to make DS happy and return
}