I have an editable list grid and following is the way i set it up
final ListGrid grid = new ListGrid();
grid.setDataSource(serverDS);
grid.setHeight(300);
// don't show header context menu
grid.setShowHeaderContextMenu (false);
grid.setAutoFetchData(true);
grid.setCanEdit(true);
grid.setEditEvent(ListGridEditEvent.CLICK);
grid.setEditByCell(true);
// DO NOT PERFORM save on edit
grid.setAutoSaveEdits (false);
If the end user edit the fields and change the value, in some other button click i would like to take all the values from the list grid and do some other operation. I have a click handler on the button that reads up the data as follows:
for(ListGridRecord record : grid.getRecords ())
{
// name and type are the ListGrid field names
String name = record.getAttribute ("name");
String type = record.getAttribute ("type");
...
}
But i still get the old values and NOT the values that are changed by the user.
How to get the new values? I tried to use various handlers but none of them works!
Can somebody please show me the correct way to handle this?
Thanks for the reply. But unfortunately endEditing () doesn’t update the new values. This is what i did on click handler of a button
grid.endEditing ();
for(ListGridRecord record : grid.getRecords ())
{
// name and type are the ListGrid field names
String name = record.getAttribute ("name");
String type = record.getAttribute ("type");
...
}
The record.getAttribute (property) is always giving back the old values and not the newly edited values.
I am not submitting the records to the server by click on this button. But instead my intension is to get the new values and do some other operations on the client side itself and later send it to server using GWT-RPC mechanism.
why don’t you link your grid to a datasource ? then, once a cell is edited the new value is saved in the datasource. Then, once the user will click on the button to end his editing you just have to get all the records of the datasource and to send them to your server to update the data in your DB ?
This is what I do for one of my grid and it is working fine.
EDIT : oups I see that you are using a datasource. So i don’t understand the issue. Why do you put the autosave to false ? this autosave would save the data in your datasource, not on your server DB so it should be better to let it at true.
Here is how i am doing the whole thing. May be i m missing some key point in my handling (this is my first experience with SmartGWT)
I have my datasource that takes an sql statement from client (GUI) and tries to gets it’s column metadata. I have a servlet (getMetaData) that responds
the data to be presented in the grid in xml and so my datasource using xpath as follows:
public class MyDataSource extends DataSource
{
....
public MyDataSource (final String sqlString)
{
....
setDataFormat (DSDataFormat.XML);
setRecordXPath ("/columns/column");
setDataURL (GWT.getModuleBaseURL () + "getMetaData");
DataSourceField nameField = new DataSourceTextField ("name",
"Name");
nameField.setPrimaryKey (true);
nameField.setRequired (true);
DataSourceField typeField = new DataSourceTextField ("type",
"Data type");
typeField.setValueMap (getSupportedTypes ());
setFields (new DataSourceField[]{nameField, typeField});
}
/*
* (non-Javadoc)
*
* @see com.smartgwt.client.data.DataSource
* #transformRequest(com.smartgwt.client.data.DSRequest)
*/
@Override
protected Object transformRequest (DSRequest dsRequest)
{
// set the sql statement as a parameter in the request
JavaScriptObject data = dsRequest.getData ();
if (dsRequest.getOperationType () == DSOperationType.FETCH)
{
JSOHelper.setAttribute (data, "sqlString", sqlString);
}
return data;
}
}
then in the grid i just point to the above data source (With auto-fetch to true).
final ListGrid grid = new ListGrid();
grid.setDataSource(myDataSource);
grid.setAutoFetchData(true);
grid.setCanEdit(true);
grid.setEditEvent(ListGridEditEvent.CLICK);
grid.setEditByCell(true);
// DO NOT PERFORM save on edit
grid.setAutoSaveEdits (false);
If the user try to edit values in the grid (if the setAutoSaveEdits to true), it tries to communicate automatically to the datasource and in turn to the server, which i surely
want to avoid. So, i put setAutoSaveEdits to false.
Everything works as expected till i just show the data in grid. But once the user edit some data in grid, i am not able to capture
the new values available in the grid as follows:
for(ListGridRecord record : grid.getRecords ())
{
// name and type are the ListGrid field names
String name = record.getAttribute ("name");
String type = record.getAttribute ("type");
...
// name and type still has the old values????
}
I am pretty sure that i m missing some key points on how the whole thing works.
Sorry i think i can’t help you there because I don’t have the same behavior on my application :
in fact i don’t link my datastore to the server. So I edit my grid, the modifications are sent to the datastore and i only launch my RPC treatment once the user click on a button Save. And this is at this moment only that I get the recod from the db and I send them all to the server.
About the issue that you had with setAutiSaveEdit() option and capturing the data, did you find the way to work with it? I’m having similar problem.
Hope you found a solution…