This is a migrated thread and some comments may be shown as answers.

Coordinating with remote update routine that adjusts field values

2 Answers 62 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 27 Sep 2017, 05:33 PM

Suppose I have a data source with fields id and x that comes from a table foobar.

The view model is id, x, xorig.  For read operations the xorig value is also set to the x value

The peculiar rules for foobar is that when an x is to be updated it will try to honor the requested x, otherwise it will return a new x value

The data source is configured for batch mode.

The read gets a row id=1, x=10

The user edits x to be 20 and hits a save changes button.  The update transport sends json via parameterMap [ {id:1, x:20, xorig:10} ]

The update routine will send back [ {id:1, x:20, xorig:20} ] if the edit was honored, or perhaps [ {id:1,x:55,xorig:55} ] if the 20 could not be honored and the peculiar rules determined x should be 55 instead.

How and where can I capture the update response and tweak the data source elements to match the update response. For example:

for (var i=0; i<updateResponseData.length; i++) {
    var responseItem = updateResponseData[i];
    var datasorcItem = myDataSource.get(responseItem.id);
    datasorcItem.x = responseItem.x;
    datasorcItem.xorig =responseItem.xorig;
    datasorcItem.dirty = false;
}

 

Thanks,

Richard

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 29 Sep 2017, 07:58 AM
Hello Richard,

If I understand correctly the scenario, it should be possible to modify the data within the requestEnd event of the DataSource, by retrieving the returned data from the response. More information on this event is available in the following help topic:
On a side note, after an update request, if you modify the passed value on server-side, once that value is returned to the DataSource it should be updated accordingly. The same could be observed when the "ID" is set for new records on server-side for example. 


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Richard
Top achievements
Rank 1
answered on 02 Oct 2017, 04:49 PM

Thanks Konstantin.

Coding a requestEnd event handler is what I needed. Addtionally the .set() method was used to perform the value assignmnents for the updated items. For example:

datasorcItem.set('x', responseItem.x);

Tags
Data Source
Asked by
Richard
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Richard
Top achievements
Rank 1
Share this question
or