gpt4 book ai didi

javascript - JqG​​rid - 使用 formatDisplayField 选项

转载 作者:行者123 更新时间:2023-12-03 10:08:50 25 4
gpt4 key购买 nike

我在使用 jqgrid 和一些选项时遇到问题,最好的写法是向您显示图像: jQGrid

所以,当我构建表体(使用ajax调用)时,我传递了一个隐藏字段。当某些内容分组时,我想显示“未定义”单词所在的隐藏字段(组标题)。

有没有使用formatDisplayField的解决方案?

我所拥有的是这样的:

groupingView : {
groupField : ['cpv'],
groupCollapse : true,
groupOrder: ['desc'],
plusicon: 'ui-icon-circle-plus',
minusicon: 'ui-icon-circle-minus',
formatDisplayField: [
function (value) { // Should be cpv_parent (hidden by default but sent to jggrid when instantiate)
console.log(value); // Contain CPV Grouped
console.log($(this)); // Contain [table#ajaxTable.ajaxTable.ui-jqgrid-btable, context: table#ajaxTable.ajaxTable.ui-jqgrid-btable, constructor: function, init: function, selector: "", jquery: "1.7.2"…]
//return String(displayValue).substring(0, 5);
}
],
isInTheSameGroup: function (x, y) {
return String(x).substring(0, 5) === String(y).substring(0, 5);
}
}

编辑根据需要,这是我正在使用的示例数据(来自上次尝试(使用 userData)):

{"total":1,"page":1,"totalrecords":3,"userdata":{"98513295":"98000000-3"},"rows":[{"tipoConcurso":"Ajuste Directo (Regime Geral)","createdOn":"2014-04-23 16:19:56","valor":15000,"cpv":98513295,"cpvParent":"98000000-3"},{"tipoConcurso":"Ajuste Directo (Regime Geral)","createdOn":"2013-10-01 16:05:08","valor":15000,"cpv":98513295,"cpvParent":"98000000-3"},{"tipoConcurso":"Ajuste Directo (Regime Geral)","createdOn":"2013-09-03 17:34:39","valor":15000,"cpv":98513295,"cpvParent":"98000000-3"}]}

谢谢@Oleg:)

提前谢谢大家:)

问候,马塞洛

最佳答案

理解你的问题有点困难,因为你只显示了一些抽象的数字。我是这么理解你的。您按cpv字段进行分组,但需要显示另一个字段cpvParent,该字段可以根据cpv值获取。只需要有一张从 cpv 获取 cpvParent 的 map 即可。我不建议添加任何更昂贵的隐藏列。

所以我建议你更改数据

{
"total": 1,
"page": 1,
"totalrecords": 3,
"rows": [
{
"tipoConcurso": "Ajuste Directo (Regime Geral)",
"createdOn": "2014-04-23 16:19:56",
"valor": 15000,
"cpv": 98513295,
"cpvParent": "98000000-3"
},
{
"tipoConcurso": "Ajuste Directo (Regime Geral)",
"createdOn": "2013-10-01 16:05:08",
"valor": 15000,
"cpv": 98513295,
"cpvParent": "98000000-3"
},
{
"tipoConcurso": "Ajuste Directo (Regime Geral)",
"createdOn": "2013-09-03 17:34:39",
"valor": 15000,
"cpv": 98513295,
"cpvParent": "98000000-3"
}
]
}

以下内容:

{
"total": 1,
"page": 1,
"totalrecords": 3,
"userdata": {
"98513295": "98000000-3",
"97123456": "97000000-2"
}
"rows": [
{
"tipoConcurso": "Ajuste Directo (Regime Geral)",
"createdOn": "2014-04-23 16:19:56",
"valor": 15000,
"cpv": 97123456,
"cpvParent": "98000000-3"
},
{
"tipoConcurso": "Ajuste Directo (Regime Geral)",
"createdOn": "2013-10-01 16:05:08",
"valor": 15000,
"cpv": 98513295
},
{
"tipoConcurso": "Ajuste Directo (Regime Geral)",
"createdOn": "2013-09-03 17:34:39",
"valor": 15000,
"cpv": 98513295
}
]
}

formatDisplayField回调中,您可以获取userData参数(参数名称为userData,但JSON数据必须具有userdata 在其他情况下)。现在,userData[value] 将通过键“98513295”为您获取“98000000-3”:

groupingView: {
groupField: ["cpv"],
...
formatDisplayField: [
function (value) {
var userData = $(this).jqGrid("getGridParam", "userData");
return userData[value];
}
]
}

这种方式见效很快,只需在服务器端按照上述格式准备数据即可。

关于javascript - JqG​​rid - 使用 formatDisplayField 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30236480/

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