gpt4 book ai didi

jquery - Jqgrid - 对行级数据进行分组

转载 作者:行者123 更新时间:2023-12-03 22:01:09 25 4
gpt4 key购买 nike

使用jqgrid,是否可以像附图中那样对行级数据进行分组?基本上我想将特定行的数据从某些列开始拆分为多行..

示例

enter image description here

最佳答案

我建议您使用cellattr在某些单元格上设置rowspan属性或设置style="display:none"隐藏另一个不需要的细胞。这个想法与 the answer 中的 colspan 相同。

作为结果,您可以创建以下网格(请参阅 the demo )

enter image description here

或另一个(参见 another demo )

enter image description here

网格的问题在于 jqGrid 的另一个功能,如排序、分页、悬停和选择。有些功能可以通过额外的努力来实现,但另一种功能则更难以实现。

我在演示中使用的代码如下:

var mydata = [
{ id: "1", country: "USA", state: "Texas", city: "Houston", attraction: "NASA", zip: "77058", attr: {country: {rowspan: "5"}, state: {rowspan: "5"}} },
{ id: "2", country: "USA", state: "Texas", city: "Austin", attraction: "6th street", zip: "78704", attr: {country: {display: "none"}, state: {display: "none"}} },
{ id: "3", country: "USA", state: "Texas", city: "Arlinton", attraction: "Cowboys Stadium", zip: "76011", attr: {country: {display: "none"}, state: {display: "none"}} },
{ id: "4", country: "USA", state: "Texas", city: "Plano", attraction: "XYZ place", zip: "54643", attr: {country: {display: "none"}, state: {display: "none"}} },
{ id: "5", country: "USA", state: "Texas", city: "Dallas", attraction: "Reunion tower", zip: "12323", attr: {country: {display: "none"}, state: {display: "none"}} },
{ id: "6", country: "USA", state: "California", city: "Los Angeles", attraction: "Hollywood", zip: "65456", attr: {country: {rowspan: "4"}, state: {rowspan: "4"}} },
{ id: "7", country: "USA", state: "California", city: "San Francisco", attraction: "Golden Gate bridge", zip: "94129", attr: {country: {display: "none"}, state: {display: "none"}} },
{ id: "8", country: "USA", state: "California", city: "San Diego", attraction: "See world", zip: "56653", attr: {country: {display: "none"}, state: {display: "none"}} },
{ id: "9", country: "USA", state: "California", city: "Anaheim", attraction: "Disneyworld", zip: "92802", attr: {country: {display: "none"}, state: {display: "none"}} }
],
arrtSetting = function (rowId, val, rawObject, cm) {
var attr = rawObject.attr[cm.name], result;
if (attr.rowspan) {
result = ' rowspan=' + '"' + attr.rowspan + '"';
} else if (attr.display) {
result = ' style="display:' + attr.display + '"';
}
return result;
};

$("#list").jqGrid({
datatype: 'local',
data: mydata,
colNames: ['Country', 'State', 'City', 'Attraction', 'Zip code'],
colModel: [
{ name: 'country', width: 70, align: 'center', cellattr: arrtSetting },
{ name: 'state', width: 80, align: 'center', cellattr: arrtSetting },
{ name: 'city', width: 90 },
{ name: 'attraction', width: 120 },
{ name: 'zip', index: 'tax', width: 60, align: 'right' }
],
cmTemplate: {sortable: false},
rowNum: 100,
gridview: true,
hoverrows: false,
autoencode: true,
ignoreCase: true,
viewrecords: true,
height: '100%',
caption: 'Grid with rowSpan attributes',
beforeSelectRow: function () {
return false;
}
});

我在上面的代码中使用了与输入数据放在一起的附加 attr 属性。这只是一个例子。我想让 cellattr 函数的实现更加简单。您可以使用相同的想法,以任何其他格式放置 cellattr 所需的信息。

关于jquery - Jqgrid - 对行级数据进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12200621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com