jQuery JQGrid:将数据加载到页脚行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2820254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:19:51  来源:igfitidea点击:

JQGrid: Loading data into the footer row

jqueryjqgrid

提问by Scot H

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

提前致谢...

回答by Oleg

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

看演示http://trirand.com/blog/jqgrid/jqgrid.html

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

并在左侧树中选择“ 3.5 版中的新功能”,然后选择“摘要页脚行”。

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

在示例footerrow : true, userDataOnFooter : true中 jqGrid 的一组选项。然后服务器将userdata块添加到发送回 jqGrid 的数据中。您可以userdatahttp://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data 中阅读。如果userdata块帽属性对应于 jqGrid 的列名,则数据将显示在页脚行中。

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

如果您需要更多信息,您应该写下您在 jqGrid 中使用的数据类型(JSON、XML、xmlstring、jsonstring、本地等)以及您使用的服务器类型(PHP、ASP.NET MVC、WCF 端等) )。

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

更新:如果您使用标准 json 从服务器映射您的数据(jqGrid 没有 jsonReader 选项)看起来像

{ 
  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: trueinside of the jqGrid options and your server should produce data like

所以数据没有来自 colModel 的列名。例如,如果您在 colModel 中有一列 {name:'price', ...} 并且想要在 jqGid 的最后一行显示总价,您应该footerrow: true, userDataOnFooter: true在 jqGrid 选项内定义,并且您的服务器应该生成如下数据

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

如果您使用另一个 jsonReader 所有 stat 不变。您唯一可以定义的是将“userdata”名称更改为另一个名称,但该值必须是具有您在 colModel 中定义的字段名称的对象。jqGrid 的最后一行仅显示此字段的值。

回答by Sanchitos

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

上面的答案很有帮助。无论如何,这是我在 MVC.Net 中的做法:

First this attributes over the grid definition:

首先这个属性在网格定义上:

footerrow: true, userDataOnFooter: true

footerrow: true, userDataOnFooter: true

In the action result on the HttpPost:

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