我需要免费的jqgrid帮助。在这里,我想显示带有某种格式的项目的简短摘要。 目前,我已经使用 setGroupHeaders 在一个组下显示多个列。但这看上去并不友好,因此我开始尝试对此进行一些更改。
关于第一张图片:当前的外观。
更新:我不清楚是否应该将第二个(结果)网格视为枢轴网格或树形网格。
更新2:我为此创建了一个小提琴,但似乎我缺少here。可以在下面找到代码示例:
var data = [{
"id": 1,
"deadline":"Deadline",
"AgreedD":"Agredd Deadline",
"labelD":"Date",
"Agreed":"2018-02-11",
},{
"id": 2,
"deadline":"Deadline",
"EstimatedD":"Estimated Deadline",
"labelD":"Date",
"Estimated":"2018-02-15"
}
, {
"id": 2,
"deadline":"DaysLeft",
"UAD":"25",
"UED":"33"
},
{
"id": 3,
"deadline":"Participants",
"RequiredP":"120",
"WRec":"88"
},
{
"id": 4,
"deadline":"Utterences",
"RequiredU":"6000",
"RecordedU":"4800"
},{
"id": 5,
"deadline":"Throughput",
"RequiredT":"400",
"ActualT":"12"
},
];
/* convert the salesdate in */
$("#list483").jqGrid("jqPivot",
data,
{
frozenStaticCols: true,
skipSortByX: true,
useColSpanStyle: true,
//defaultFormatting: false,
**xDimension**: [
{dataName:"deadline"},
{dataName: "AgreedD" },
{dataName: "EstimatedD" },
{dataName: "WRec", sortorder: "desc" },
{dataName: "UED", sortorder: "desc" },
{dataName: "Estimated", sortorder: "desc" },
],
**yDimension**: [
{ dataName: "Agreed", width: 100, label: "Agreed" },
{ dataName: "Estimated", width: 100, label: "Estimated" },
{dataName:"RequiredP", width: 100, label: "RequiredP"},
{dataName:"UAD", width: 100, label: "UAD"},
{dataName:"RequiredU", width: 100, label: "RequiredU"},
{ dataName: "salesYear", sorttype: "integer" },
{ dataName: "salesMonth", sorttype: "integer" }
],
**aggregates**: [{
//member: "Agreed",
//template: "number",
//template: "integer", //myIntTemplate,
},
{
member: "totalnumberofsales",
aggregator: "count",
//template: "integer",
label: "{0}"
}]
},
// grid options
{
iconSet: "fontAwesome",
cmTemplate: { autoResizable: true, width: 75 },
shrinkToFit: false,
useUnformattedDataForCellAttr: false,
autoResizing: { compact: true },
groupingView: {
//groupField: ["x2"],
groupColumnShow: [false],
groupText: ["<span class='group-text'>{0}</span>"]
},
//width: 450,
pager: true,
rowNum: 20,
//caption: "<b>statistics</b>",
rowList: [5, 10, 20, 100, "10000:All"]
});
//var p = $("#list483").jqGrid("getGridParam");
//console.log(JSON.stringify(p.pivotOptions.xIndex));
//console.log(JSON.stringify(p.pivotOptions.yIndex));
因此,如果有人可以指导我介绍一些示例,这将非常有帮助。
答案 0 :(得分:2)
使用jqPivot
功能无法轻松实现您所描述的内容,因为您显示的数据结构似乎未遵循特定规则(某些记录包含一个单元格的值,而其他记录则包含值两个单元格。)
似乎您只需要显示一条记录,记录的值分为两行,而不需要jqGrid提供的功能,在这种情况下,我建议您不要使用网格插件,而只需手动创建DOM。
但是,如果要使用jqgrid,我的建议是先处理数据,然后再将其传递给jqgrid,然后将其转换为更适合小部件的结构。
您可以使用以下网格配置来实现所需的UI:
var dataConverted = convertData(data); //Convert your custom data to the structure of colModel
$('#grid').jqGrid({
//...
datatype: "local",
data: dataConverted,
colModel: [
{name: 'deadlineType', label: 'Deadline'},
{name: 'deadlineValue', label: ''},
{name: 'daysLeftType', label: 'Days left'},
{name: 'daysLeftValue', label: ''},
{name: 'participantsType', label: 'Participants'},
{name: 'participantsValue', label: 'Total'},
{name: 'qaPassed', label: 'QA passed'}
]
});
* colspan,align,date formatter等所需的细微调整
如果列是动态的,则在处理数据时也可以生成colModel
。