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

Insert a row with data into grid

0 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 23 May 2012, 08:50 PM
Hi,

I have already created a new 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,

LCG

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Luis
Top achievements
Rank 1
Share this question
or