Search code examples
restsmartgwt

Send all data from row (not only changed) during update request from ListGrid in SmartGWT


Currently I'm trying to customize SmartGWT's DataSource to work with custom REST services. And I hit into problem with sending update requests when some changes have been made in the ListGrid row. By default only changed cells in the row are sent in update request (as described here). And I want to change this behavior to send all data from the row not just edited. I've already spent a lot of time figuring out how to do this but still can't find a solution. Could you please give me any advice how to change this OOTB behavior? Probably someone has had similar problem and found the solution.


Solution

  • Here is the way how I implement sending all data from the row during update request. Probably it will help someone.

    I overrode transformRequest method and added there such code:

    @Override
    protected Object transformRequest(final DSRequest dsRequest) {
        ...
        if (dsRequest.getOperationType = OperationType.UPDATE) {
           ...
           final JavaScriptObject basicJSObject = dsRequest.getOldValues().getJsObj();
           final JavaScriptObject latestChanges = dsRequest.getData();
           JSOHelper.addProperties(basicJSObject, latestChanges);
    
           // Regexp probably can be optimized
           final String resultString = JSON.encode(responseData)
                .replaceAll("[,]\\s*[,]", ",")
                .replaceAll("^\\s*[,]", "")
                .replaceAll("[,]\\s*$", "");
    
           return resultString;
        }
        ...
    }