JqGrid - 使用formatDisplayField选项 [英] JqGrid - Using formatDisplayField Option
问题描述
我在使用带有一些选项的jqgrid时遇到了问题,写的更好的是给你一个图像:
I'm with a problem using jqgrid with some options, better that write is show you an image:
所以,当我构建表体(带有ajax调用)时,我正在传递一个隐藏字段。当某些内容被分组时,我想显示隐藏字段,其中'undefined'字是(组标题)。
So, when I'm construction the table body (with ajax call) I'm passing an hidden field. When something is grouped, I want to show that hidden field where 'undefined' word is (group title).
是否有使用 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)):
EDIT As required, heres a sample data form what i'm using (from last try (using 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:)
提前谢谢大家:)
问候,
Marcelo
Regards, Marcelo
推荐答案
理解你的问题有点困难,因为你展示了一些抽象的nu只有mbers。我理解你。您通过 cpv
归档进行分组,但是您需要显示另一个字段 cpvParent
,可以根据<$获取c $ c> cpv 价值。只需要从 cpv
获得 cpvParent
的地图。我不建议添加任何更贵的隐藏列。
It's a little difficult to understand your question because you display some abstract numbers only. I understand you so. You make grouping by cpv
filed, but you need to display another field cpvParent
which can be get based on the cpv
value. One need just to have a map which get cpvParent
from cpv
. I don't recommend to add any hidden columns which are more expensive.
所以我建议您更改数据
{
"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
Inside of formatDisplayField
callback you can get userData
parameter (the name of parameter is userData
, but the JSON data have to have userdata
in other case). Now the userData[value]
will get you "98000000-3"
by key "98513295"
:
groupingView: {
groupField: ["cpv"],
...
formatDisplayField: [
function (value) {
var userData = $(this).jqGrid("getGridParam", "userData");
return userData[value];
}
]
}
这种方式可以快速完成您需要以上述格式在服务器端准备数据。
Such way will work quickly and you need just prepare the data on the server side in the above format.
这篇关于JqGrid - 使用formatDisplayField选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!