editable ListGrid and changed values

Hi,

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.
fargo

Maybe this topic can help you with it:
http://forums.smartclient.com/showthread.php?t=2278

Take a look at the endEditting() function.
That should submit everything to the server.

Hi Diether,

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.

Thx.

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.

Regards

Thanks Olinsha and Diether for the replies.

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.

Thanks for your help.

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.

I hope you will have help for your issue

Regards

fargo,
Look for the ListGrid.getEdit* methods that were recently added to SVN. For example ListGrid.getEditValues

Sanjiv

Hi Sanjiv,

Thanks for the pointer. But unfortunately i got the following behaviour

 for(int i= 0; i< grid.getRecords ().length; i++)
 {
     System.out.println (grid.getEditValues (i).size ()); // here is the error
     String name = record.getAttribute ("name");
     String type = record.getAttribute ("type");
 }
Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): 'fieldName' is undefined
 number: -2146823279
 description: 'fieldName' is undefined
	at com.smartgwt.client.widgets.grid.ListGrid.getEditValues(Native Method)

Before i try it out, i just wanted to have a look at the size of the map. Am i doing something wrong here?

Can you try now after refreshing SVN?

I took the latest from here
http://smartgwt.build.rorschach.de/

but still the same error for

System.out.println (grid.getEditValues (i).size ());

Thx.

But apart from the error that i mentioned the following does work to get the post-edited values

for(int i= 0; i< grid.getRecords ().length; i++)
{
String name = record.getAttribute (“name”);
String type = record.getAttribute (“type”);

 if (grid.getEditValue (i, "name") != null)
 {
    name = grid.getEditValue (i, "name").toString ();
 }
                            
 if (grid.getEditValue (i, "type") != null)
 {
    type = grid.getEditValue (i, "type").toString ();
 }

}

Thank you all for all the help. Thanks Sanjiv for providing edit* functions. It helps a lot!

Having the same issue & getting same result.

Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): 'fieldName' is undefined
 number: -2146823279
 description: 'fieldName' is undefined
	at com.smartgwt.client.widgets.grid.ListGrid.getEditValues(Native Method)

Which version are you using? Have you tried it with v1.0b2, or against SVN?

Hi fargo,

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…