简体   繁体   English

在Kendo网格中更改数据源

[英]Change datasource in Kendo grid

I have added demo in jsfiddle . 我在jsfiddle添加了演示。 This code works perfectly in google chrome (I didn't check with other browsers). 这段代码在谷歌浏览器中是完美的(我没有与其他浏览器一起查看)。 Which means the field and datasource are perfectly replaced. 这意味着字段和数据源已完全替换。 But while convert it as android app using phonegap and cordova.js it works like this demo (Here the datasource is append to the previous one). 但是,当使用phonegap和cordova.js将其转换为android应用时,它的工作原理类似于此演示(此处的数据源将追加到上一个示例中)。 I don't know what happens. 我不知道会发生什么

If this question didn't clear please let me know. 如果这个问题不能解决,请告诉我。

Thanks in advance. 提前致谢。

Not sure about whether you want to add row or replace whole grid contents. 不确定要添加行还是替换整个网格内容。 But it will solve both the problems. 但这将解决两个问题。 You can try this. 你可以试试看

Working Fiddle 工作小提琴

To add extra data 添加额外的数据

 function changedata() {

    var grid = $("#grid").data("kendoGrid");
    grid.dataSource.add({ name: "John Doe", age: 33});
    grid.dataSource.add({ name: "Jane Doe", age: 30}

     );
  }

To Replace the data. 替换数据。

function replacedata() {
 $("#grid").data("kendoGrid").dataSource.data([{ name: "aaaa Doe", age: 30 },{ name: "aaaa Doe", age: 23 }]);
  }

You should use a current version of Kendo UI so you can use the destroy method, for example. 例如,您应该使用Kendo UI的当前版本,以便可以使用destroy方法。 Your change handler should then look like this: 然后,您的变更处理程序应如下所示:

function changedata() {
    $("#grid").data("kendoGrid").destroy();
    $("#grid").empty();

    $("#grid").kendoGrid({
        dataSource: [{
            name: "Jane Doe",
            age: 30,
            no: 11
        }, {
            name: "John Doe",
            age: 33,
            no: 12
        }]
    });
}

( demo ) 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM