将特定数据放在jqgrid摘要视图标题中 [英] Put specific data in jqgrid summary view header

查看:96
本文介绍了将特定数据放在jqgrid摘要视图标题中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作的jqgrid表,该表在标题上具有摘要视图,就像我在此处在此plunkr中实现的示例一样 http://plnkr.co/edit/wjIlaVMsa9vusmfhgfL1?p=preview .

I have a working jqgrid table that has summary view on the header, just like this example that I implemented in this this plunkr here http://plnkr.co/edit/wjIlaVMsa9vusmfhgfL1?p=preview.

摘要视图标题正常工作,并且显示的数据来自jqgrid中的(sum)函数.

The summary view header works fine, and the data displayed comes from (sum) function in the jqgrid.

但是,我不想让jqgrid自己计算摘要,而是要在摘要行中显示我自己的数据(并且仍然按列显示,我不希望使用colspan摘要标题).最简单的示例是:假设我的列下的数据均为文本.我仍然想要分组和摘要视图标题和在摘要标题上显示每列的数据,但是我不希望jqgrid为我计算摘要(因为它是文本).我想显示自己的摘要数据,该数据也来自我的数据json.

However, instead of letting the jqgrid calculate the summary by itself, I want to display my own data in the summary row (and still per column, I dont want a colspan summary header). Easiest example will be: suppose the data under my columns are all text. I still want to have grouping & summary view header & show data per column on the summary header, but I don't want jqgrid to calculate the summary for me (since it's a text). I want to display my own summary data, which comes also from my data json.

我不认为使用

summaryTpl: '<b>{0}<b>'

将为我工作,因为我要显示的数据来自我的json数据.

will work for me since the data that I want to display comes from my json data.

这可能吗? 如果我的解释不够清楚,请告诉我.谢谢!

Is this possible? Let me know if my explanation is not clear enough. Thank you!

推荐答案

您发布的演示使用jqGrid 4.6版本.在这种情况下,您不太可能设置自定义摘要值.您可以在需要放置自定义摘要值的列中使用自定义格式化程序.我在旧答案中描述了该方法.这真的很棘手.

The demo which you posted uses jqGrid 4.6 version. You have not so much possibility to set custom summary value in the case. You can use custom formatter in the column where you need to place custom summary value. I described the approach in the old answer. It's really tricky.

或者,我建议您使用免费jqGrid 4.8 (请参见第一个来自您的原始演示. 第二个包含

Alternatively I can suggest you to use free jqGrid 4.8 (see readme and wiki). Free jqGrid supports summaryType defined as function. To show how it works I created some JSFiddle examples for you. The first one consist from your original demo. The second one contains

summaryType: function (v, cn, record) {
    var fieldData = parseInt(record[cn], 10);
    return v === "" ? fieldData : fieldData + v; 
}

而不是summaryType: "sum".摘要列中的结果将接近原始列,但我使用的是parseInt(record[cn], 10)而不是parseFloat(record[cn]).所以我只得到输入数字的整数部分,结果也将是整数.

instead of summaryType: "sum". The results in summary column will be close to the original one, but I used parseInt(record[cn], 10) instead of parseFloat(record[cn]). So I get only integer part of the input numbers and the results will be integer too.

下一个演示包含静态变量

var mySummary = {
    ALFKI: 12,
    ANATR: 23,
    AROUT: 34,
    BERGS: 45,
    BLAUS: 56
};

和看起来像

summaryType: function (v, cn, record) {
    return mySummary[record.CustomerID];
}

将根据mySummary图显示每个组的摘要结果.我提醒您,这些值将使用您在该列中定义的相同格式器进行格式化.因为您在Freight列中使用了formatter: 'number',所以结果应该是数字或可以转换为数字的字符串.

In the way the summary results for every group will be displayed based on the mySummary map. I remind you that the values will be formatted by the same formatter which you defined in the column. Because you use formatter: 'number' in the column Freight, then the results should be numbers or the string which can be converted to numbers.

最后一个演示使用修改后的JSON数据

The last demo uses modified JSON data

{
    "userdata": {
        "ALFKI": 12.34,
        "ANATR": 23.45,
        "AROUT": 34.56,
        "BERGS": 45.67,
        "BLAUS": 56.78
    },
    "rows":[
        ....
    ]
}

我这样定义的summaryType

summaryType: function (v, cn, record) {
    var userData = $(this).jqGrid("getGridParam", "userData");
    return userData[record.CustomerID];
}

结果,分组摘要中显示的值来自服务器的userdata部分.我认为这就是您想要的.

As the result the values displayed in the grouping summary come from the userdata part of the server. I think it's what you want.

这篇关于将特定数据放在jqgrid摘要视图标题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆