Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQGrid: Loading data into the footer row

Tags:

jquery

jqgrid

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...

like image 221
Scot H Avatar asked May 12 '10 15:05

Scot H


2 Answers

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.

like image 71
Oleg Avatar answered Oct 21 '22 16:10

Oleg


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);
        }
like image 34
Sanchitos Avatar answered Oct 21 '22 18:10

Sanchitos