【发布时间】:2014-07-30 07:50:01
【问题描述】:
我有一个剑道 UI 网格,我从 Javascript 绑定下面是相同的代码。
我的问题是,当我选中复选框并向下滚动网格并向上滚动时,即使我转到下一页,选中的复选框也未选中,然后也会遇到同样的问题。
$(gridName).html("");
var fieldSchema = [];
var columnSchema = [];
columnSchema.push({
field: "",
width: "30px",
template: "<input id='chkDelete' type='checkbox' />",
});
var counter = 0;
$.each(data, function (index) {
counter = counter + 1;
var xmldoc = $.parseXML(data[index].CustomFields);
var $xml = $(xmldoc);
var jsonStr = '{';
$xml.find("Fields").find("Field").each(function () {
jsonStr = jsonStr + '"' + $(this).attr("Title").replace(/\s/g, '').replace(/[^\w\s]/gi, '') + '":{';
jsonStr = jsonStr + '"Title":"' + $(this).attr("Title") + '",';
jsonStr = jsonStr + '"Value":"' + $(this).attr("Value") + '",';
jsonStr = jsonStr + '"Id":"' + $(this).attr("Id") + '"},';
if (counter == 1) {
columnSchema.push({
field: $(this).attr("Title").replace(/\s/g, '').replace(/[^\w\s]/gi, '') + ".Value",
title: $(this).attr("Title"),
width: "128px",
template: "#=" + $(this).attr("Title").replace(/\s/g, '').replace(/[^\w\s]/gi, '') + ".Value#",
});
}
});
jsonStr = jsonStr + '"CustomFields":"' + data[index].CustomFields.replace(/\"/g, "\'") + '",';
jsonStr = jsonStr + '"ValidationPlanId":"' + data[index].ValidationPlanId + '",';
jsonStr = jsonStr + '"IsTrCreated":"' + data[index].IsTrCreated + '",';
jsonStr = jsonStr + '"Note":"' + data[index].Note + '",';
jsonStr = jsonStr + '"IsUpdate":"' + data[index].IsUpdate + '",';
jsonStr = jsonStr + '"TestRequestId":"' + data[index].TestRequestId + '"';
jsonStr = jsonStr + '}';
fieldSchema.push($.parseJSON(jsonStr));
});
var dtVpAdd = new kendo.data.DataSource({
data: fieldSchema,
schema: {
model: {
id: "ValidationPlanId"
},
total: function (result) {
var totalCount = result.length;
return totalCount;
}
}
});
dtVpAdd.pageSize(10);
$(gridName).kendoGrid({
dataSource: new kendo.data.DataSource({
data: fieldSchema,
schema: {
model: {
id: "ValidationPlanId"
}
},
pageSize: 10
}),
columns: columnSchema,
filterable: true,
sortable: {
mode: "multiple",
allowUnsort: true
},
scrollable: {
virtual: true
},
resizable: true,
reorderable: true,
pageable: {
input: true,
numeric: false
},
dataBound: function () {
$(gridName).on('click', '#chkDeleteAll', function () {
var checked = $(this).is(':checked');
$("input[id*='chkDelete']:checkbox").attr('checked', checked);
});
},
});
【问题讨论】:
-
网格中的复选框有点棘手,因为您无法在不进入编辑模式的情况下更新它们(单击复选框)。你有没有记住这一点?如果没有,您会看到已标记的复选框,但模型实际上并未更新,因此当您加载新数据(页面、滚动、过滤器等)时,更改会丢失。
标签: javascript jquery asp.net-mvc-4 kendo-ui kendo-grid