仅在旧值和新值不同时,才在编辑时比较和显示kendo脏标志的方法,然后再保存网格 [英] How to compare and display kendo dirty flag upon editing only if the old value and new value are different before saving the grid
问题描述
在剑道网格中,当我更改值时,在网格单元格中会显示剑道的脏标志.但是,当我单击返回同一网格单元并将其更改为先前的值(已经存在的值)时,脏标志仍会出现.
In a kendo grid, in grid cell when I change a value kendo's dirty flag is displayed. But then when I click back to the same grid cell and change it to the previous value (already existing value) the dirty flag still appears.
如何检查该值是否与先前的值相似,并且在保存之前不显示脏标志.
How can I check whether the value is similar to the previous value and not display the dirty flag before saving.
下面是我的剑道可编辑下拉菜单代码.
Below is my code for kendo editable dropdown.
function editCategoryDropDown(container, options) {
var catObject = JSON.parse(ticketProjectCategoryObject.value);
$('<div id="categoryDDTreeView" class="dropDownTreeViewStyle"/>').appendTo(container);
var catDropDownTreeView = $("#categoryDDTreeView").kendoExtDropDownTreeView({
treeview: {
dataSource: new kendo.data.HierarchicalDataSource({
data: catObject
}),
//expended: true,
loadOnDemand: false,
change: function (e) {
{
var dropDownTreeViewObj = $('#categoryDDTreeView').find('.k-input');
var nodeTitle = dropDownTreeViewObj.attr("title");
if (nodeTitle != null) {
options.model.Category = nodeTitle;
options.model.CategoryId = dropDownTreeViewObj.attr("nodevalue")
options.model.dirty = true;
container.addClass("k-dirty-cell");
}
};
}
},
}).data("kendoExtDropDownTreeView");
var dropDownBox = catDropDownTreeView.dropDownList();
dropDownBox.text(options.model.Category)
var treeView = catDropDownTreeView.treeview();
var node = treeView.findByText(options.model.Category.split("|").pop().trim());
treeView.select(node);
}
推荐答案
这是一项有趣的任务,因此我花了一些时间进行实验.考虑以下方法:
This is an interesting task, so I invested some time in experimenting. Consider the following approach:
-
事件,将数据项(
e.model.toJSON()
)的原始状态保存在某个变量中.需要toJSON
才能剥夺剑道特定的字段和方法,将数据项转换为普通的JavaScript对象,并破坏通过引用传递数据项时原本会发生的自动值更新.
edit
中的in the
edit
event of the Grid, save the original state of the data item (e.model.toJSON()
) in some variable.toJSON
is needed to strip the Kendo-specific fields and methods, convert the data item to a plain JavaScript object and break the automatic value updates that will otherwise occur, as the data item is passed by reference.
edit: function(e) {
var model = e.model;
if (!originalDataItems[model.id]) {
originalDataItems[model.id] = model.toJSON();
}
}
这是一个完整的示例:
要指出的一件事是,即使脏标记将被隐藏,但相应的数据项仍为 batch
时,这是一个小问题使用编辑方式(根据您的情况),但是如果要防止不必要的数据传输,请增强save
处理程序并将未修改的数据项的dirty
字段重置为false
.
One thing to point out is that even though the dirty marks will be hidden, the respective data item will still be dirty
and subject to syncing with the remote data service. This is a minor issue when batch
editing is used (as in your case), but if you want to prevent unnecessary data transfer, enhance the save
handler and reset the unmodified data items' dirty
field to false
.
这篇关于仅在旧值和新值不同时,才在编辑时比较和显示kendo脏标志的方法,然后再保存网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!