我正在使用kendo ui创建丰富的用户界面,但我坚持以下内容: 我想要一个带有子网格的网格,第一个显示客户信息,如名称等,第二个显示可用的送货地址,客户保存。现在我的问题是,虽然firebug显示,但子网格中的数据不是数据,而是返回了数据。这是我的来源:
$(function() {
var main = $("#customer-grid").kendoGrid({
dataSource: {
transport:{
read :"data/users.php",
update :{
url :"data/users.php?action=update",
type:"POST",
data: function (data) {
data.birthday = kendo.toString(data.birthday, "yyyy-MM-dd");
return data;
}
},
destroy:{
url :"data/users.php?action=destroy",
type:"POST"
}
},
schema: {
data: "data",
model: {
id: "id",
fields: {
id: {editable: false},
activated: { type: "boolean" },
birthday: {type: "date"},
gender: {defaultValue: "W"}
}
}
}
},
height: 250,
filterable: true,
sortable: true,
pageable: true,
detailInit: detailInit,
dataBound: function() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
},
columns: [{
field: "id",
title: "ID",
width: "50px"
}, {
field: "gender",
title: "Geschlecht",
width: "100px",
values: data
}, {
field: "firstname",
title: "Vorname"
}, {
field: "lastname",
title: "Nachname"
}, {
field: "birthday",
title: "Geburtstag",
width: "100px",
format: "{0:dd.MM.yyyy}"
},{
field: "mail",
title: "E-Mail"
},{
field: "activated",
title: "Aktiviert",
width: "100px",
values: actval
}, {
command: ["edit", "destroy"],
title: " ",
width: "210px"
}],
editable:{
mode: "popup"
}
});
});
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
transport: {
read: "data/adress.php?uid="+e.data.id
},
serverPaging: true,
serverSorting: true,
serverFiltering: true,
pageSize:6
},
scrollable: false,
sortable: true,
pageable: true,
columns: [
{ field: "id", width: 70 },
{ field: "zipcode", title:"Ship Country", width: 100 },
{ field: "city", title:"Ship Address" },
{ field: "street", title: "Ship Name", width: 200 }
]
});
}
该函数从php页面获取数据,该页面执行mysql查询,然后将数据作为application / json返回。但没有显示任何内容。
希望你们能帮助我。
此致
答案 0 :(得分:1)
我测试了你的代码,它运行正常。
检查:
e
参数格式。我用过:detailInit({ detailCell : $("#grid"), data : { id : 1}});
data/adress.php
返回的JSON。我回来了:[ {"city":"Madrid", "id":"1", "zipcode":"31000", "street":"my street 1", "number":5}, {"city":"Sofia", "id":"2", "zipcode":"32000", "street":"my street 2", "number":4}, {"city":"London", "id":"3", "zipcode":"33000", "street":"my street 3", "number":3}, {"city":"San Francisco", "id":"4", "zipcode":"34000", "street":"my street 4", "number":2}, {"city":"Berlin", "id":"5", "zipcode":"35000", "street":"my street 5", "number":1} ]
使用以下(硬编码)php响应:
<?php
header('Content-type: application/json');
$named_array = array(
array("city" => "Madrid", "id" => "1", "zipcode" => "31000", "street" => "my street 1", "number" => 5),
array("city" => "Sofia", "id" => "2", "zipcode" => "32000", "street" => "my street 2", "number" => 4),
array("city" => "London", "id" => "3", "zipcode" => "33000", "street" => "my street 3", "number" => 3),
array("city" => "San Francisco", "id" => "4", "zipcode" => "34000", "street" => "my street 4", "number" => 2),
array("city" => "Berlin", "id" => "5", "zipcode" => "35000", "street" => "my street 5", "number" => 1)
);
echo json_encode($named_array);
?>
编辑:这是包含子网格的网格的定义。
var outer = $("#outer").kendoGrid({
dataSource:{
type:"json",
transport:{
read:"names.php"
},
pageSize:5
},
sortable:true,
columns:[
{ field:"id", width:70 },
{ field:"name", title:"Name", width:100 },
{ field:"lastname", title:"LastName", width:100 },
{ title:"Address", width:300, attributes:{ class:"ob-address"}}
]
}).data("kendoGrid");
然后点击按钮,我运行:
$(".ob-address", outer.tbody).each(function (idx, elem) {
detailInit({ detailCell:elem, data:{ id:1}});
});
如您所见,我在outer
网格中使用名为ob-address
的CSS类标记了一列,该函数选择outer
表正文中的所有单元格以插入内表(子网格)。