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

saveChanges custom implementation

1 Answer 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 28 Mar 2015, 08:45 PM
Hi,

I would like to handle saveChanges on grid myself as I want to send additional data to server. So far, this is what I have done:

var allData = stateMap.projectStaffDs.data();
var models = $.grep(allData, function (item) { // grab only dirty rows
        return item.dirty;
});
 
                  // save
                   var xhr = $.ajax({
                       type: "POST",
                       cache: false,
                       url: document.getBaseUrl() + "/Services/SaveStaff",
                       contentType: "application/json; charset=utf-8",
                       dataType: "json",
                       data: JSON.stringify({ data: models, workspace: "custom" }),
                       success: function(data) {
                           console.log("project staff saved");
                       },
                       beforeSend: function(xhr) {},
                       error: function (xhr, textStatus, errorThrown) {
                           console.log(errorThrown);
                       }
                   });

My concern now is, after I save changes on the server, how to update the DataSource locally so that if reflects no changes and that all changes saved?

More or less, I want to call "sync()", but would that update the datasource locally?

Thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Apr 2015, 06:38 AM
Hello,

Could you provide the code for the grid dataSource so I can check the exact setup? Generally speaking the sync method can be used to reset modified and deleted items but new records should still be assigned a non-default ID.
Also, if you wish to use custom code for the request then I can also suggest to use custom functions for the transport operations.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Bilal
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Share this question
or