简体   繁体   English

Kendo UI:按钮单击事件时动态更改网格的dataSource

[英]Kendo UI: Dynamically change dataSource of grid on button click event

I am having 2 Json files ie Products.json and Promotions.json . 我有2个Json文件,即Products.jsonPromotions.json Both are having the same structure ie fields are same just the values are different. 两者具有相同的结构,即字段相同,只是值不同。

When the page gets loaded the grid is bound with the data in Products.json as follows: 加载页面后,网格将与Products.json中的数据绑定,如下所示:

<!--dataSource gets the Products.json data -->
<div data-role="grid" data-columns="[{field:'code',title:'Code'} .... data-bind="source: dataSource"></div> 

after which on button click I want to clear the current records of grid and add data of Promotions.json 之后在按钮上单击我想清除网格的当前记录并添加Promotions.json的数据

<div data-role="grid" data-columns="[{field:'code',title:'Code'} .... data-bind="source: applyPromotionsDataSource"></div> 

I am able to read both the dataSources successfully, also I am successfully able to get the "click" event as well.. 我能够成功读取两个dataSources,也能够成功获取“ click”事件。

Questions 问题

  1. How shall I clear the existing dataSource of the grid? 如何清除网格的现有dataSource?

  2. How shall I bind the new dataSource to the grid? 如何将新的数据源绑定到网格? (using what method?) (使用什么方法?)

setDataSource()方法效果很好,但是如果列中的数据源也不同,则会发生错误,原因是找不到“ xxxNewDataSourceColumn”列...是否有一种方法也可以刷新列?

I got the solution for the above issue. 我得到了上述问题的解决方案。

I went through the documentation of grid and came across the setDataSource() method and added it on the button click event. 我浏览了网格文档,并遇到了setDataSource()方法,并将其添加到按钮单击事件中。

That worked well. 效果很好。

Those looking into this issue, Thanks!! 那些正在调查这个问题的人,谢谢! :) :)

-Hardik -Hardik

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

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