English 中文(简体)
如何将项目添加到 kendo ui 网格的数据源中?
原标题:How can I add items to the data source of a kendo ui grid

我创建了Kendo. data. Data. 数据来源 成功, 我能够把它绑在网页上的KendoUI网格上。

但当我尝试 data source. Info:0, [a: "b"] ; 时,它会删除先前的数据。

我的例子代码如下:

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"}]
});

这就是我如何与电网连接:

$("#association-grid").kendoGrid({
height: 99,
columns:
[
    {
        field: "ID",
        title: "ID"
    },
    {
        field: "Name",
        title: "Name"
    },
    {
        field: "NameID",
        title: "NameID"
    }
],

dataSource: tempSource
});

这就是我如何增加一个新项目:

tempSource.insert(0, { ID: "John Smith", Name: "Product Description", NameID: "123 1st Street" });

如果我在将数据绑到网格之前执行添加,我就会失去最初在数据源对象上的前两个项目。

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.

谢谢

VRC 甚RC

最佳回答

尝试此选项 :

dataSource.add({ name: "John Smith", description: "Product Description", address: "123 1st Street" });
问题回答
var grid = $("#itemsGrid").data("kendoGrid");

                    for (var i = 0; i < data.length; i++) {

                        grid.dataSource.insert(data[i]);
                    }

在网格数据源中插入新记录





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签