0

I am using struts2 jqgrid i want to know if there is a method which i can use to show the number of sub groups in a group. For example

-grp1.   Total records 8 total sub groups 2
 +subgrp1 total records 4
 +subgrp2 total records 4
-grp2    Total records 6 total sub groups 1
 +subgrp1 total records 6
+grp3 Total records 6 total sub groups 2

how can i display the number of subgroup in a group

i can get the Total records 6 by using

Total records: {1}

I cant find how to get the sub grid total

Haider
  • 615
  • 1
  • 16
  • 38
  • 1
    it could be important to know whether you use local grouping or server side grouping. I mean: do you calculated already the values which you want to display and your problem is displaying the values only or you need to calculate the values too? Do you tried to use grouping summary (see [the documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping#options_and_methods))? By the way: do you seen [the answer](http://stackoverflow.com/a/16152739/315935) and [this one](http://stackoverflow.com/a/10805487/315935)? – Oleg Jul 25 '14 at 10:03
  • My reply is the same posted as first comment on second answer but only first 2 lines – Haider Jul 25 '14 at 11:12
  • 1
    @Haider What do you have in mind _My reply is the same posted as first comment on second answer but only first 2 lines_ – Roman C Jul 25 '14 at 11:40
  • @Haider: Sorry, but could you express you more clear. I don't understand what you mean. – Oleg Jul 25 '14 at 11:54
  • Thank you for replying.... my project wouldn't' be where it is at without all your answers on Stackoverflow. :) – Haider Jul 25 '14 at 12:21
  • @Haider: If you want post the solution of your problem you should better write *the answer* on your question. You can include the reference on [my old answer](http://stackoverflow.com/a/10805487/315935) which code you used in your solution. Later you can accept your answer. – Oleg Jul 26 '14 at 06:43
  • @Oleg please check if it can be optimized – Haider Jul 26 '14 at 10:10
  • @Haider: You don't provide *a demo* (for example [jsfiddle](http://jsfiddle.net/) demo, see [the video](https://www.youtube.com/watch?v=zrWkRHSK6A8) if you new in jsfiddle) which demonstrates the the code work. If I *just read* your code I can say only the following: it should work correctly if you want to display the number of subgroups on the **next level** and not **subgroups of all child levels**. – Oleg Jul 26 '14 at 11:14
  • 1
    @Haider: I see only two places where one can improve performance (a little bit only): 1) replace `names = new Object()` to `names = {}` 2) save `item.grp2` in additional variable and use it instead: `var gName;` at the beginning and replace `names[item.grp2] = item.grp2;` to `gName = item.grp2; names[gName] = gName;`. In general such small changes in the code are nor really important. – Oleg Jul 26 '14 at 11:18
  • @Oleg i am facing a issue that when user filter data = $(this).jqGrid("getGridParam", "data"); returns all the recorde not the filtrered ones, is there function to get only the filtered records – Haider Dec 28 '14 at 13:54
  • @Haider: Look at [the answer](http://stackoverflow.com/a/9831125/315935). It described the way how you could access records *filtered* locally. – Oleg Dec 28 '14 at 15:39

1 Answers1

0

Thanks to Oleg, this solved my problem and solution is

function groupFormater(cellval, opts, rowObject, action)
{

    var groupIdPrefix = opts.gid + "ghead_", 
    groupIdPrefixLength = groupIdPrefix.length,
    names = {}, data, i, l, item;    

    if (opts.rowId.substr(0, groupIdPrefixLength) === groupIdPrefix && 
              typeof action === "undefined") 
    {           
        data = $(this).jqGrid("getGridParam", "data");
        for (i = 0, l = data.length; i < l; i++) {
             item = data[i];
             if (item.grp1 === cellval) {
                 names[item.grp2] = item.grp2;
             }
         }
        return cellval + " Total sub group : " + Object.keys(names).length;
    }       
    return  cellval;
}
Community
  • 1
  • 1
Haider
  • 615
  • 1
  • 16
  • 38