稱爲填充與數據模型如果有人仍有意在該主題的操作方法我還沒有找到如何使用ASP.NET包裝解決問題。然而,也可以使用純HTML和JS來解決這個問題,具體如下:
<section id="root-grid">
<div class="panel">
<div class="grid"></div>
</div>
</section>
<script type="text/x-kendo-template" id="slave-template">
<div class="panel">
<div class="grid"></div>
</div>
</script>
<script type="text/javascript">
$(function() {
var data = @Html.Raw(Json.Encode(Model.FacilitySchedules));
var columns = [
makeKendoColumn("ValidFrom", "@Resources.DealerFacility_ValidFrom", "{0:d}", "date"),
// other columns
];
var detailColumns = [
// as above - columns definition
];
OnRootScheduleGridInitialize(
data,
columns, detailColumns,
$('#root-grid').find('.grid'));
});
</script>
腳本:
function OnRootScheduleGridInitialize(dataObject, columnsDefinition, subGridColumnsDefinition, $node) {
$node.kendoGrid({
dataSource: {
data: dataObject,
schema: {
model: {
fields: {
// root model fields definition
}
}
},
pageSize: 20
},
scrollable: true,
sortable: true,
pageable: {
input: true,
numeric: false
},
columns: columnsDefinition,
detailTemplate: kendo.template($("#slave-template").html()),
detailInit: OnDetailsScheduleInitializeFactory(subGridColumnsDefinition),
});
}
function OnDetailsScheduleInitializeFactory(columnsDefinition) {
return function (e) {
var $row = e.detailRow;
$row.find('.grid').kendoGrid({
dataSource: {
data: e.data.FacilityScheduleItems,
schema: {
model: {
fields: {
// slave object model fields definition
}
}
},
pageSize: 20
},
scrollable: true,
sortable: true,
pageable: {
input: true,
numeric: false
},
columns: columnsDefinition,
});
};
}
function makeKendoDateColumn(columnName, columnLabel) {
return makeKendoColumn(columnName, columnLabel, 'd', 'date');
}
function makeKendoNumericColumn(columnName, columnLabel) {
return makeKendoColumn(columnName, columnLabel, 'n', 'number');
}
function makeKendoGenericColumn(columnName, columnLabel) {
return {
field: columnName,
title: columnLabel,
width: '100px',
};
}
function makeKendoColumn(name, label, format, attrClass) {
var maker = function (n, l, f, c) {
var result = {
width: '100px'
};
n(result);
l(result);
f(result);
c(result);
return result;
}
var nameDec = function (r) { r.field = name; };
var labelDec = function (r) { r.title = label; };
var attrDec = function() { };
var formatDec = function() { };
if (attrClass) {
attrDec = function (r) { r.attributes = { "class": attrClass }; };
formatDec = function (r) { r.format = format; };
}
else {
if (format) {
attrDec = function (r) { r.attributes = { "class": attrClass }; };
}
}
return maker(nameDec, labelDec, formatDec, attrDec);
}
如果您有任何其他的解決方案,請與大家共享。
據我瞭解,這創建了一個POST請求到服務器,我不想。我想使用本地數據。 – SOReader
你可以顯示你在哪裏定義本地數據 – CSharper
它是用來渲染頁面的模型。注意'ServerOperation'設置爲'null'和'BindTo'方法。 – SOReader