jquery - 如何在 Kendo UI Grid 的 onDataBound 事件中检查现有行值是否更改?
问题描述
我在 Asp.Net MVC 中使用 Kendo UI Grid。
我在文档就绪函数中调用了以下事件。
function RefreshGrid() {
setInterval(function () {
$("#MediaBatchGrid").data("kendoGrid").dataSource.read();
$(".k-loading-image").hide();
}, 5000);
}
每当向服务器发出请求时调用上述函数。整个数据将绑定在剑道网格 UI 中。所以,问题是,网格闪烁甚至保留网格中的现有值。我担心的是,如何在客户端停止这种闪烁?如果新数据与现有值不同,那么只有在数据绑定事件上才会发生怎么办,否则返回并且不需要在网格中更改任何 UI
解决方案
我为此挣扎了一段时间,最后,我找到了简单的解决方案。
我们应该在 HTML 中为数据绑定定义一个事件。IE,
.Events(x => x.DataBinding("Grid_DataBinding"))
jQuery代码:
Grid_DataBinding = function (e) {
var displayedData = $("#Grid").data().kendoGrid.dataSource.view();// this is to get Existing values from Grid
var displayedDataAsJSON = JSON.stringify(displayedData);
// then convert it as JSON
var newData = e.sender._data;// to get new data coming from Server
var newDataAsJSON = JSON.stringify(newData);// convert it too as JSON
if (newDataAsJSON === displayedDataAsJSON) {// Equal check
e.preventDefault();// if both are equal, just prevent data binding event
$(".k-loading-mask").hide();// this is to avoid grid flickering, hiding loader too
}
}
推荐阅读
- opencv - opencv中的无损jpeg压缩
- javascript - 如何在 Typescript/JavaScript 中显示两个数组之间的差异?
- azure - 错误:错误升级连接:错误拨号后端:拨号tcp
:10250: i/o 超时 - r - 如何在 R 中加载 .tif 光栅文件
- javascript - jQuery datepicker 语言(本地化)如何在语言之间切换
- php - 更改 WooCommerce 中显示的运费总额
- javascript - 创建一个有两个参数的函数,参数 a 将是一个数组,参数 b 将在数组中找到一个元素
- c++ - 链接 .dll MinGW C++
- css - 如何覆盖 ng-bootstrap datepicker element.style
- c++ - 为什么当我将变量推送到向量上时,它没有推送我期望的值?