I am hoping someone can shed some light on the proper method for handling batch updates on a grid when the backend data source is an XML based web service.
Here are the particulars:
I would like to use the built in update, create and delete properties of the datasource transport, at the same time, I need to manipulate the data being sent to the web service from json to xml (the reader is json, the writer is xml). The caveat to this is I need to update the actual cell value being updated not a whole record (model) at a time. The problem with doing this strictly in the datasource (as far as I can tell) is that I cannot get details about which column changed only that the record (model) was updated.
Is there a way without putting in handlers within the KendoGrid to identify which fields have changed during the parameterMap callback so I can output just those individual values that have changed in a batch mode?
Here is what I did, but I would like to avoid putting a handler in the grid (if possible):
I put an event handler off the save property of the KendoGrid to record a list of changed cells. Then, on the ParameterMap of the data source, I go through the records and build the proper xml.
Is this the right approach or is there a better way to do this all within the datasource?
Here is my KendoGrid definition:
Then, the onCellChanged:
And the datasource definition
And finally the parameterMap (crud operations):
Here are the particulars:
I would like to use the built in update, create and delete properties of the datasource transport, at the same time, I need to manipulate the data being sent to the web service from json to xml (the reader is json, the writer is xml). The caveat to this is I need to update the actual cell value being updated not a whole record (model) at a time. The problem with doing this strictly in the datasource (as far as I can tell) is that I cannot get details about which column changed only that the record (model) was updated.
Is there a way without putting in handlers within the KendoGrid to identify which fields have changed during the parameterMap callback so I can output just those individual values that have changed in a batch mode?
Here is what I did, but I would like to avoid putting a handler in the grid (if possible):
I put an event handler off the save property of the KendoGrid to record a list of changed cells. Then, on the ParameterMap of the data source, I go through the records and build the proper xml.
Is this the right approach or is there a better way to do this all within the datasource?
Here is my KendoGrid definition:
$(this._renderTo).kendoGrid({ dataSource: this.ItemsDS, sortable: true, pageable: true, navigatable: true, editable: true, save: $.proxy( this.onCellChanged, this ), columns: [ { field: "Position.Name", title: "Position", width: 20 }, { field: "Headcount.value", title: "Headcount", width: 15 }, { field: "FTE.value", title: "FTE", width: 15 }, { field: "EmployeeName.value", title: "EmployeeName", width: 50 }, { field: "JobCode.value", title: "JobCode", width: 20 }, { field: "JobTitle.value", title: "JobTitle", width: 100 } ]});Then, the onCellChanged:
onCellChanged: function (e) { var isDirty = false; var fieldName = e.container[0].firstChild.name; if (!fieldName) return; var newValue = e.values[fieldName]; var oldValue = e.model[fieldName] if (newValue != oldValue) { var esResults = this.ItemsDS._pristine.EmployeeListResponse.Results; elemName = fieldName; // Create the record that will be sent back to TM1 this._employeeUpdates.items.push({ Scenario: esResults.Scenario, Position: e.model.Position, Employee: e.model.Employee, EntityDept: esResults.EntityDept, ProductLine_s: esResults.ProductLine_s, Employee_m: { ID: elemName }, Value: newValue }); e.container.data("oldValue", newValue); }},And the datasource definition
this.ItemsDS = new kendo.data.DataSource({ transport: { read: { url: this._url + "/EmployeeList", dataType: "json" }, update: { url: this._url + "/TM1ViewWrite", dataType: "xml" }, parameterMap: $.proxy(this._crudItemDS, this) }, pageSize: 15, schema: { : : : : :And finally the parameterMap (crud operations):
_crudItemDS: function (options, operation) { if (operation == "update") { if (this._employeeUpdates) { return { events: kendo.stringify(this._employeeUpdates) }; }; } return null;},