[原创]EasyUI的DataGrid合计汇总页脚使用教程
- ASP.NET MVC
- 2011-11-29
- 267热度
- 0评论
最近做订单处理,需要汇总订单明细的数量和金额,所以涉及到使用EasyUI的Datagrid组件的页脚汇总功能,先看了一下官方教程,如下:
Tutorial » Displaying Summary Information in DataGrid's Footer
In this tutorial, we will show you how to display the summary rows in the footer of datagrid.

To display footer row, you should set the showFooter property to true and then prepare the footer rows that is defined in datagrid data. Below is the sample data:
- {"total":1,"rows":[{"id":1,"name":"Chai","price":18.00}],"footer":[{"name":"Total","price":18.00}]}
Create DataGrid
- <table id="tt" title="DataGrid" class="easyui-datagrid" style="width:400px;height:250px"
- url="data/datagrid17_data.json"
- fitColumns="true" rownumbers="true" showFooter="true">
- <thead>
- <tr>
- <th field="name" width="80">Product Name</th>
- <th field="price" width="40" align="right">Unit Price</th>
- </tr>
- </thead>
- </table>
The footer rows are same as body rows, so you can display more than one summary information on footer.
Download the EasyUI example:
[csharp]
public Dictionary getOrderList(string ordercode)
{
Dictionary result=new Dictionary();
if (String.IsNullOrEmpty(ordercode))
{
result.Add("total",1);
result.Add("rows", new BuyOrderList());
result.Add("footer", new { Goods_Name = "合计", Buy_Number = 0, Order_Amount=0 });
return result;
}
else
{
List datas = new BusinessLogic().Select(new BuyOrderList() { Order_Code = ordercode });
result.Add("total", datas.Count);
result.Add("rows", datas);
List footer=new List();
footer.Add(new BuyOrderList(){Identifier=-2,Goods_Name="合计:",Buy_Number=datas.Sum(m => m.Buy_Number),Order_Amount=datas.Sum(m => m.Order_Amount)});
result.Add("footer",footer);
return result;
}
}
[/csharp]