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

ClientDataSource update sends several requests

4 Answers 30 Views
ClientDataSource
This is a migrated thread and some comments may be shown as answers.
Omar
Top achievements
Rank 1
Omar asked on 01 Dec 2016, 01:06 PM

Hi, I'm using ClientDataSource connected to a webservice and using OnCustomParameter to customize the data request.

I noticed that if I changed several fields for a data item and updated the clientdatasource, then for each field modified a request is sent to the webservice.

Each request has a single field changed from the previous one.

Suppose I have in a dataitem 4 fields (a,b,c,d) with their initial value to 1,

now I need to modify them to {a : 2, b:2, c:2, d:2}

when I update the clientdatasource the following requests are sent:

request1: {a:2,b:1,c:1,d:1}

request2: {a:2,b:2,c:1,d:1}

request3: {a:2,b:2,c:2,d:1}

request4: {a:2,b:2,c:2,d:2}

Is there a way to only send the final request? i.e. I want to get all the data updated before syncing.

4 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 06 Dec 2016, 11:12 AM
Hello Omar,

Can you please share the code that you are using for updating the item and elaborate on the exact scenario. Using the update method as demonstrated in the following online demo should initiate only one request for the update:
Looking forward to your reply.


Regards,
Konstantin Dikov
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
Omar
Top achievements
Rank 1
answered on 11 Dec 2016, 07:21 AM

The javascript code for updating the datasource: (dropdownlist, numerictextbox, numerictextbox,textbox)

var data = {
    EmergencyCategoryID: emergency_cat.get_selectedItem().get_value(),
    Injuries: emergency_inj.get_value(),
    Casualties: emergency_cas.get_value(),
    Description: emergency_desc.get_value(),
};
 
try {              
    emergencyClientDataSource.update(data,emergency_data.ID);
} catch (e) {
    console.log(e);
}

 

The javascript code for custom paramter:

function EmergencyClientDataSource_OnCustomParameter(sender, args) {
    console.log("Custom Emergency parameter: ", sender, args);
    var data = args.get_data();
    if (!data) {
        data = {};
    }
 
    data['username'] = window.sessionStorage["username"];
    switch (args.get_type()) {
        case "update":
            var update_data = {
                username: data.username,
                emergencyid: data.ID,
                description: data.Description,
                categoryid: data.EmergencyCategoryID,
                injuries: data.Injuries,
                casualties: data.Casualties,
            }
            args.set_parameterFormat(update_data);
            break;
    }
    console.log(data, args.get_parameterFormat());
};

 

RadClientDataSource:

<telerik:RadClientDataSource ID="EmergencyClientDataSource" runat="server" AutoSync="true">
    <ClientEvents OnDataParse="EmergencyClientDataSource_OnDataParse" OnChange="EmergencyClientDataSource_OnChange"
        OnCustomParameter="EmergencyClientDataSource_OnCustomParameter"/>
    <Schema DataName="Result" ResponseType="JSON" ErrorsName="ErrorMessage">
        <Model ID="ID">
            <telerik:ClientDataSourceModelField FieldName="ID" DataType="String" Nullable="true" Editable="False" />
            <telerik:ClientDataSourceModelField FieldName="EmergencyCategoryID" DataType="String" Nullable="false" Editable="False" />
            <telerik:ClientDataSourceModelField FieldName="Description" DataType="String" />
            <telerik:ClientDataSourceModelField FieldName="Casualties" DataType="Number" />
            <telerik:ClientDataSourceModelField FieldName="Injuries" DataType="Number" />
        </Model>
    </Schema>
</telerik:RadClientDataSource>

 

After I execute the update I get the following in the console:

emergencyid: 3287e04d-342c-411d-b95d-397af479b9e2 injuries: 5 casualties: 100 description: qwertyuhgfdsertyu categroyid: 81a93455-a9dc-4596-b4e4-2e64b4411d38
 
emergencyid: 3287e04d-342c-411d-b95d-397af479b9e2 injuries: 5 casualties: 5 description: qwertyuhgfdsertyu categroyid: 81a93455-a9dc-4596-b4e4-2e64b4411d38
 
emergencyid: 3287e04d-342c-411d-b95d-397af479b9e2 injuries: 5 casualties: 5 description: qwerty categroyid: 81a93455-a9dc-4596-b4e4-2e64b4411d38
 
response Object {ErrorMessage: null, IsSuccessful: true, Result: Object}
response Object {ErrorMessage: null, IsSuccessful: true, Result: Object}
response Object {ErrorMessage: null, IsSuccessful: true, Result: Object}

As you can see only as single field is modified at a time, and three requests are generated!

 

0
Accepted
Konstantin Dikov
Telerik team
answered on 14 Dec 2016, 01:51 PM
Hello Omar,

Can you please try to set the AutoSync property of the RadClientDataSource to "false" and call the sync method manually after calling the update method?

Please give this a try and let me know if the issue is resolved.


Regards,
Konstantin Dikov
Telerik by Progress
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
Omar
Top achievements
Rank 1
answered on 18 Dec 2016, 05:45 AM

Hi Konstantin,

Thank you for your repsonse. I removed autosync and used sync and it worked.

Tags
ClientDataSource
Asked by
Omar
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Omar
Top achievements
Rank 1
Share this question
or