I have a grid that is initiated with a local datasource. I have a schema and a parse that manipulates the data received. I need to replace the datasource but don't want to retype the entire schema over again. How can I do that? I have an example dojo here. In my example, I am adding 100 to the age. Notice that after reloading the new records don't have the 100 added to the age. I need to know how to do this for the entire grid and also for updating a single record in the grid. I tried pushUpdate for a single record and it ignores the parse also.
http://dojo.telerik.com/OxazIqAG
Here is the relevant code:<script>
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "age" },
{ field: "id" }
],
dataSource: {
data: [
{ id: 1, name: "Jane Doe", age: 30 },
{ id: 2, name: "John Doe", age: 33 }
],
schema: {
parse: function(response) {
var users = [];
for (var i = 0; i < response.length; i++) {
let record = response[i];
var user = {
id: record.id,
name: record.name,
age: record.age + 100
};
users.push(user);
}
return users;
},
model: {
id: "id",
fields: {
id: { type: "number" }
}
}
}
}
});
$("#setData").click(function(){
$("#grid").data("kendoGrid")
.dataSource
.data([{id: 3, name: "new item", age: 20}]);
});
</script>