1

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.

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

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.

I dont think using

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

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!

blenzcoffee
  • 851
  • 1
  • 11
  • 35

1 Answers1

2

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.

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; 
}

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.

The next demo contains static variable

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

and the summaryType which looks as

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

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.

The last demo uses modified JSON data

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

The summaryType I defined so

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

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • hi Oleg, thanks for the reply! Is the technique mentioned in free jqGrid 4.8 supported in jqGrid 4.8 (http://www.trirand.com/blog/?p=1467) ? I am only allowed to use jqGrid and not other forked library.. – blenzcoffee Apr 01 '15 at 00:08
  • @blenzcoffee: You are welcome! You should test it yourself, whether it's supported by Guriddo jqGrid JavaScript 4.8... There are no more jqGrid. You can ask on [Grriddo forum](http://guriddo.net/?page_id=4). – Oleg Apr 01 '15 at 00:17
  • No more jqGrid? Do you mean the last version is jqGrid 4.8? (I'll check the forum). I'm trying your answer now. I already have my user data when I'm setting the jqGrid options, so I'm going with the static variable way. I'll see how it goes. Thanks! – blenzcoffee Apr 01 '15 at 00:22
  • @blenzcoffee: You are welcome! You can ask on [Grriddo forum](http://guriddo.net/?page_id=4) if you purchased the product. – Oleg Apr 01 '15 at 00:23
  • hi Oleg, turns out jqGrid 4.6.0 supports summaryType as function too :) so I used the technique described in your old answer. thank you very much! this is very, very helpful! – blenzcoffee Apr 01 '15 at 05:11