当我在jqGrid中加载我的treegrid时,我想让我的数据崩溃,但即使我在每一行上都有“expanded:false”,叶子也不会隐藏。我必须在三角形上单击两次才能折叠它们。
如果是jqGrid错误,有没有办法以编程方式折叠所有行?
我正在使用jqgrid 4.5.2
JSON示例
[{"SearchID":"1307101033122572934","Name":"Merisier","Count":2474,"PmpSum":1239238,"Cost":614702,"level":0,"isLeaf":false,"expanded":false,"parent":null,"Type":"SpeciesId","loaded":true,"Mpmp":496.03,"PmpAvg":500,"ID":0},
{"Count":456,"Name":"V1","PmpSum":211519,"SearchID":"1307101126533057710","Cost":115880,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":0,"PmpAvg":463,"Mpmp":547.85,"ID":1},
{"Count":476,"Name":"V2","PmpSum":234671,"SearchID":"1307101126480002486","Cost":117369,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":0,"PmpAvg":493,"Mpmp":500.14,"ID":2},
{"Count":516,"Name":"V3","PmpSum":266814,"SearchID":"1307041126098777710","Cost":127569,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":0,"PmpAvg":517,"Mpmp":478.12,"ID":3},
{"Count":520,"Name":"V5","PmpSum":261883,"SearchID":"1307101126567002934","Cost":128510,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":0,"PmpAvg":503,"Mpmp":490.72,"ID":4},
{"Count":506,"Name":"V4","PmpSum":264351,"SearchID":"1307041126002272486","Cost":125374,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":0,"PmpAvg":522,"Mpmp":474.27,"ID":5},
{"SearchID":"1307041018095682486","Name":"Tremble","Count":2492,"PmpSum":1192850,"Cost":618840,"level":0,"isLeaf":false,"expanded":false,"parent":null,"Type":"SpeciesId","loaded":true,"Mpmp":518.79,"PmpAvg":478,"ID":6},
{"Count":452,"Name":"V2","PmpSum":206778,"SearchID":"1307101126480002486","Cost":116551,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":6,"PmpAvg":457,"Mpmp":563.65,"ID":7},
{"Count":536,"Name":"V3","PmpSum":257211,"SearchID":"1307041126098777710","Cost":129121,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":6,"PmpAvg":479,"Mpmp":502,"ID":8},
{"Count":506,"Name":"V1","PmpSum":268536,"SearchID":"1307101126533057710","Cost":121648,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":6,"PmpAvg":530,"Mpmp":453,"ID":9},
{"Count":469,"Name":"V4","PmpSum":221601,"SearchID":"1307041126002272486","Cost":119857,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":6,"PmpAvg":472,"Mpmp":540.87,"ID":10},
{"Count":529,"Name":"V5","PmpSum":238724,"SearchID":"1307101126567002934","Cost":131663,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":6,"PmpAvg":451,"Mpmp":551.53,"ID":11},
{"SearchID":"1307101127175798158","Name":"Cerisier","Count":2491,"PmpSum":1288927,"Cost":622444,"level":0,"isLeaf":false,"expanded":false,"parent":null,"Type":"SpeciesId","loaded":true,"Mpmp":482.92,"PmpAvg":517,"ID":12}]
我的网格
$("#InventorySummary").jqGrid({
datatype: 'jsonstring',
datastr: summary,
colNames: ['ID', 'SearchId', 'Type', 'NOM', 'NBRE DE BILLOTS', 'VOL. MOYEN', 'VOLUME EN PMP', 'TAUX/MPMP', 'MONTANT EN $ USA'],
colModel: [
{ name: 'ID', index: 'ID', hidden: true, key: true },
{ name: 'SearchID', index: 'SearchID', hidden: true },
{ name: 'Type', index: 'Type', hidden: true },
{ name: 'Name', index: 'Name' },
{ name: 'Count', index: 'Count' },
{ name: 'PmpAvg', index: 'PmpAvg' },
{ name: 'PmpSum', index: 'PmpSum' },
{ name: 'Mpmp', index: 'Mpmp' },
{ name: 'Cost', index: 'Cost' },
],
caption: "Inventory",
height: 'auto',
footerrow: true,
treeGrid: true,
treeGridModel: 'adjacency',
ExpandColumn: 'Name',
gridComplete: function () {
var grid = $("#InventorySummary");
var data = grid.jqGrid('getGridParam', 'data').filter(function (x) {
return x.parent === null;
});
var count = data.reduce(function (x, y) { return x + y.Count }, 0);
var pmpSum = data.reduce(function (x, y) { return x + y.PmpSum }, 0);
var cost = data.reduce(function (x, y) { return x + y.Cost }, 0);
grid.jqGrid('footerData', 'set', { Name: "TOTAUX" });
grid.jqGrid('footerData', 'set', { Count: count });
grid.jqGrid('footerData', 'set', { PmpAvg: (pmpSum / count) | 0 });
grid.jqGrid('footerData', 'set', { PmpSum: pmpSum });
grid.jqGrid('footerData', 'set', { Mpmp: Math.round(((cost / pmpSum) * 1000) * 100) / 100 });
grid.jqGrid('footerData', 'set', { Cost: cost });
},
jsonReader: {
repeatitems: false,
root: function (obj) {
return obj;
},
},
onSelectRow: filterDetail,
});
UPDATE:这是filterDetail函数。它只在另一个网格中过滤
function filterDetail(id) {
var grid = $("#InventorySummary");
var search = [];
do {
search.push({ id: grid.getCell(id, 'SearchID'), type: grid.getCell(id, 'Type') });
id = grid.getCell(id, 'parent');
}
while (Boolean(id));
var newLogs = logs.filter(function (x) {
return search.every(function (s) {
return x[s.type] === s.id;
});
});
$("#InventoryLogs").jqGrid("clearGridData").jqGrid("setGridParam", { data: newLogs, }).trigger("reloadGrid");
}
答案 0 :(得分:4)
在jqgrid内部进行混乱之后,事实证明你需要将json中的parent属性设置为字符串,而不是整数:
[{"SearchID":"1307101033122572934","Name":"Merisier","Count":2474,"PmpSum":1239238,"Cost":614702,"level":0,"isLeaf":false,"expanded":false,"parent":null,"Type":"SpeciesId","loaded":true,"Mpmp":496.03,"PmpAvg":500,"ID":0},
{"Count":456,"Name":"V1","PmpSum":211519,"SearchID":"1307101126533057710","Cost":115880,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":"0","PmpAvg":463,"Mpmp":547.85,"ID":1},
{"Count":476,"Name":"V2","PmpSum":234671,"SearchID":"1307101126480002486","Cost":117369,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":"0","PmpAvg":493,"Mpmp":500.14,"ID":2},
{"SearchID":"1307041018095682486","Name":"Tremble","Count":2492,"PmpSum":1192850,"Cost":618840,"level":0,"isLeaf":false,"expanded":false,"parent":null,"Type":"SpeciesId","loaded":true,"Mpmp":518.79,"PmpAvg":478,"ID":3},
{"Count":452,"Name":"V2","PmpSum":206778,"SearchID":"1307101126480002486","Cost":116551,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":"3","PmpAvg":457,"Mpmp":563.65,"ID":4},
{"Count":536,"Name":"V3","PmpSum":257211,"SearchID":"1307041126098777710","Cost":129121,"level":1,"isLeaf":true,"expanded":false,"Type":"GradeId","loaded":true,"parent":"3","PmpAvg":479,"Mpmp":502,"ID":5}]