I have created a kendo.data.dataSource with success, and I am able to bind it to the KendoUI Grid on my page.
But when I try to dataSource.insert(0, [a : "b"]);
it removes the data that was there previously.
My example code follows:
var tempSource = new kendo.data.DataSource({
data: [{"ID":1,"Name":"Cliente 1","NameID":"1 - Cliente 1"},{"ID":2,"Name":"Cliente 2","NameID":"2 - Cliente 2"}]
});
This is how I'm binding to the grid:
$("#association-grid").kendoGrid({
height: 99,
columns:
[
{
field: "ID",
title: "ID"
},
{
field: "Name",
title: "Name"
},
{
field: "NameID",
title: "NameID"
}
],
dataSource: tempSource
});
This is how I add a new item:
tempSource.insert(0, { ID: "John Smith", Name: "Product Description", NameID: "123 1st Street" });
If I perform the add before binding the data to the Grid, I lose the first two items that were originally on the dataSource object.
In summary: I have a pre-created dataSource binded to a Grid. I want to be able to add a new item to the dataSource, and then refresh the Grid so that the new item appears.
Thanks,
VRC
Bind data to Kendo Grid by using AJAX Read action method. Change the datasource on change event of any HTML controls. Normally, a developer can bind the data to Grid by using AJAX Read method. This read method is ActionResult method in MVC which will return JSON DataSourceResult & direclty bind the data to Grid.
The data source of the Grid holds the items that will be rendered inside the widget. An item can be a JavaScript object which represents a valid data source configuration, a JavaScript array, or an existing kendo.
Adds an empty data item to the grid. In "incell" and "inline" editing mode a table row will be appended. Popup window will be displayed in "popup" editing mode.
try this:
dataSource.add({ name: "John Smith", description: "Product Description", address: "123 1st Street" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With