JQGrid: Loading data into the footer row
Asked Answered
H

2

7

Are there any examples for loading data into the footer? I can't find any or I'm being blocked at work.

Thanks in advance...

Hookworm answered 12/5, 2010 at 15:25 Comment(1)
What do you mean by the footer? Can you give us a screen shot?Keening
A
17

Look at demo http://trirand.com/blog/jqgrid/jqgrid.html

and choose on the left tree "New in Version 3.5" and then "Summary Footer Row".

In the example one set footerrow : true, userDataOnFooter : true option of the jqGrid. Then server add userdata block to the data sent back to jqGrid. You can read about userdata in http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data. If userdata block hat properties corresponds to the column names of the jqGrid, the data will be seen in the footer row.

If you need more information you should write which kind of data you use in jqGrid (JSON, XML, xmlstring, jsonstring, local and so on) and what kind of server do you use (PHP, ASP.NET MVC, WCF end so on).

UPDATED: If you use standard json mapping your data (no jsonReader option of jqGrid) from server look like

{ 
  total: "xxx", 
  page: "yyy", 
  records: "zzz",
  rows : [
    {id:"1", cell:["cell11", "cell12", "cell13"]},
    {id:"2", cell:["cell21", "cell22", "cell23"]},
      ...
  ]
}

So the data has no name of columns from colModel. If you have, for example, one column {name:'price', ...} inside of colModel and want to show total price in the last row of jqGid you should define footerrow: true, userDataOnFooter: true inside of the jqGrid options and your server should produce data like

{ 
  total: "xxx", 
  page: "yyy", 
  records: "zzz",
  rows : [
    {id:"1", cell:["cell11", "cell12", "cell13"]},
    {id:"2", cell:["cell21", "cell22", "cell23"]},
      ...
  ],
  userdata: {price:1240.00} 
}

If you use another jsonReader all stat unchanged. The only which you can define is to change "userdata" name to another name, but the value must be an object with the field name like you defined in colModel. Only values of this fields will be shown fat on the last row of jqGrid.

Ansilme answered 12/5, 2010 at 16:0 Comment(2)
@Oleg: Another great answer Oleg, one additional question though, how do you get the "Totals" label in the footer row like in the demo you marked above?Carisacarissa
To answer my previous question I just went back into the user data and added in a value of "Totals" into the column name of the preceding field.Carisacarissa
L
4

The answer above helps a lot. Anyway here is the way I did it in MVC.Net:

First this attributes over the grid definition:

footerrow: true, userDataOnFooter: true

In the action result on the HttpPost:

        [HttpPost]
        public ActionResult GetNewMembersByDate(string date1, string date2)
        {
            List<uspGetNewByDateResult> list =_reportsRepository.GetNewByDate(DateTime.Parse(date1), DateTime.Parse(date2));

            var amount = from p in list
                         select p.Quantity;


            var jsonData = new
            {
                total = 1,
                page = 1,
                records = list.Count(),
                userdata = new
                    {
                        Name = "Total:",
                        Quantity= amount.Sum().ToString()
                    },
                rows = (
                        from row in list
                        select new
                        {
                            i = row.RowNumber,
                            cell = new[] {
                                row.RowNumber.ToString(),
                                row.Name,
                                row.Quantity.ToString()
                            }
                        }).ToArray()

            };
            return Json(jsonData);
        }
L answered 10/5, 2011 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.