1

I am using this jqgrid

        $("#griglia-navgrid").jqGrid( { 
        url: 'search.do?report='+r,
        datatype: "json",
        colNames:[ ...    ],              
            colModel:[ ...    ],
            rowNum:50,
        rowList:[20,50,100],
        pager: '#pager',
        autowidth:true,
        height:'auto',
            viewrecords: true,
        sortname: "MATNR",
            sortorder: "asc",
            footerrow : true,
            userDataOnFooter: true, 
            jsonReader: {
                root:"INVDATA",
                page: "CURRPAGE",
                total: "TOTALPAGES",
                records: "TOTALRECORDS",
                repeatitems: false,
                id: "0",
                userdata: "USERDATA",
            }
        }); //jqGrid

On server side I calculate the totals and I use "userdata" like this:

"userdata":{"total":1234,"name":"Totals"}

And it's works. Now I need to show 2 footer row with totals. And i try something like this:

"userdata":[{"total":1234,"name":"Totals"},{"total":5678,"name":"Totals"}]

But does not work. Is it possible add two footer rows using "userdata"? How can I do this?

Giacomo Savioli
  • 167
  • 3
  • 6
  • 14

1 Answers1

0

You can use my old answer as a basis of the solution which you need. It shows how to add two rows in the footer.

If you examine the source code of jqGrid for the usage of userDataOnFooter option you would find that in case of usage datatype: "json" it's only one line of code:

if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }

So jqGrid just get the value of userData parameter (the userdata in the JSON response from the server) and uses it as the parameter of footerData method. So you can just remove userDataOnFooter option and uses the approach described in the referenced above answer to add two rows in the footer with the information from userData.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg. I'm almost done :D But one thing, when I create the second row, I have to fill it field by field like this: " $newFooterRow.find(">td[aria-describedby=" + this.id + "_invdate]").text("Grand Total:"); " ? – Giacomo Savioli Nov 04 '13 at 15:32
  • @GiacomoSavioli: You are welcome! Sorry, but I don't understand your question. The grid from my demo had the column with `name: "invdate"`. So I used the selector `">td[aria-describedby=" + this.id + "_invdate]"` to fill the cell in the column `invdate` in the second row. You need replace `invdate` part of the selector with another name from `colModel` which you use. – Oleg Nov 04 '13 at 17:32
  • Sorry I didn't explain clear. To fill the 1st row i used $this.jqGrid("footerData", "set", data[0]); I thought to fill the second row, I could use something like this. But I could not, so I used: $newFooterRow.find(">td[aria-describedby=" + this.id + "_VRKME]").text(data[i].VRKME); for each column. Another question, is it possible to add n footer row? – Giacomo Savioli Nov 05 '13 at 09:09
  • @GiacomoSavioli: Sorry, but I still don't understand your current question. Do you can now successfully add the second footer and fill it or you still have some problems? – Oleg Nov 05 '13 at 09:11
  • I solved the problem, at the moment I'll add 2 footer row. However, in the future, I could have the need to add 2-3-4..n footer rows. Is it possible? – Giacomo Savioli Nov 05 '13 at 09:22
  • @GiacomoSavioli: [The answer](http://stackoverflow.com/a/13703037/315935) demonstrates how *manually* add and fill additional row in the footer and how to fill new row. The code just clone the first row of the footer, clan some properties of the row and append it after the first footer row (see call of `insertAfter`). You can use the same code to add mutiple rows in the footer. – Oleg Nov 05 '13 at 09:30