既存のリストを知っていますか、State
または表示しているものとは異なるリクエストでリストを取得できますか?もしそうなら、あなたはすることができます:
var data = [
{State: "Finished", JobID: 1234, Owner: "John"},
{State: "Finished", JobID: 5678, Owner: "Joe"},
{State: "Active", JobID: 8765, Owner: "Jane"},
{State: "Active", JobID: 4321, Owner: "Jill"}
];
var element = $("#grid").kendoGrid({
dataSource: {
data : [
{State: "Finished"},
{State: "Active"}
],
pageSize: 10
},
height : 450,
sortable : true,
pageable : true,
detailInit: detailInit,
columns : [
{
field: "State",
title: "State"
}
]
});
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
transport: {
read: function (operation) {
operation.success(data);
}
},
pageSize : 6,
filter : { field: "State", operator: "eq", value: e.data.State }
},
scrollable: false,
sortable : true,
pageable : true,
columns : [
{ field: "State", width: 70 },
{ field: "JobID", title: "JobID", width: 100 },
{ field: "Owner", title: "Owner" }
]
});
}
ここではdata
、取得したコンテンツとして使用しますが、関数内の関数を変更することがDataSource
できます。detailInit
read
url
既存のリストがわからない場合はstates
、の結果を指定してJavaScript関数を実装できDataSource
、別のリストを返しますState
。次のようになります。
var data = null;
// Create a DataSource for reading the data
var dataSource = new kendo.data.DataSource({
transport: {
read: function (op) {
data = ([
{State: "Finished", JobID: 1234, Owner: "John"},
{State: "Finished", JobID: 5678, Owner: "Joe"},
{State: "Active", JobID: 8765, Owner: "Jane"},
{State: "Active", JobID: 4321, Owner: "Jill"}
]);
initGrid(data);
}
}
});
dataSource.read();
// Function that receives all the data and Creates a Grid after eliminating
// duplicates States
function initGrid(data) {
var element = $("#grid").kendoGrid({
dataSource: {
transport: {
read: function (operation) {
var states = [];
var result = [];
$.each(data, function (idx, elem) {
if (!states[elem.State]) {
states[elem.State] = true;
result.push({ State: elem.State });
}
});
operation.success(result);
}
},
pageSize : 10
},
height : 450,
sortable : true,
pageable : true,
detailInit: detailInit,
columns : [
{
field: "State",
title: "State"
}
]
});
}
// Function that creates the inner Grid and uses originally read
// data for avoiding going to the server again.
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
transport: {
read: function (operation) {
operation.success(data);
}
},
pageSize : 6,
filter : { field: "State", operator: "eq", value: e.data.State }
},
scrollable: false,
sortable : true,
pageable : true,
columns : [
{ field: "State", width: 70 },
{ field: "JobID", title: "JobID", width: 100 },
{ field: "Owner", title: "Owner" }
]
});
}