Articles in this section
Category / Section

How to display summary row at both top and bottom of the Grid?

4 mins read

To display the summary row in both top and bottom of the grid

Solution:

For displaying the summary row in both top and bottom we have cloned the summaryRow and have inserted the cloned element before the grid content in the dataBound event of the grid. 

Script

function dataBound(args) {
        var summaryRow = $("#"+this._id+" .e-gridfooter").clone();//get the clone element of grid footer
        summaryRow.css("border", "1px solid #c4c4c4");
        summaryRow.insertBefore("#"+this._id+" .e-gridcontent");//insert the cloned element before the grid content
    }

 

 

JS

$(function () {
            $("#Grid").ejGrid({
                /// the datasource "window.gridData" is referred from jsondata.min.js
                dataSource: window.gridData,
                allowPaging: true,
                showSummary: true,
                dataBound:"dataBound",
                summaryRows: [
                    { title: "Total =", summaryColumns: [{ summaryType: ej.Grid.SummaryType.Sum, displayColumn: "Freight", dataMember: "Freight", format: "{0:C2}" }] },
                             ],
                columns: [
                    { field: "OrderID", headerText: "Order ID", isPrimaryKey: true },
                    { field: "CustomerID", headerText: "Customer ID" },
                    { field: "EmployeeID", headerText: "Employee ID"},
                    { field: "Freight", headerText: "Freight",format: "{0:C}" }
                ]
            });
        });

 

MVC

  @(Html.EJ().Grid<object>("Grid")
        
          .Datasource((IEnumerable<object>)ViewBag.data)
          .AllowPaging()    
          .ShowSummary()
          .SummaryRow(sum =>
          {
              sum.SummaryColumns(co => co.Prefix("Total = ").SummaryType(SummaryType.Sum).DataMember("Freight").DisplayColumn("Freight").Format("{0:C}").Add()).Add();
          })          
        .Columns(col =>
        {
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();
            col.Field("CustomerID").HeaderText("Customer ID").Add();
            col.Field("EmployeeID").HeaderText("Employee ID").Add();
            col.Field("Freight").HeaderText("Freight"). Format("{0:C}").Add();
        })        
        .ClientSideEvents(eve=>eve.DataBound("dataBound"))
        )

 

ASP.NET

  <ej:Grid ID="Grid1"  AllowGrouping="True" AllowPaging="True" runat="server" >
           <SummaryRows>
                <ej:SummaryRow Title="Total=">
                    <SummaryColumn>
                        <ej:SummaryColumn SummaryType="Sum" Format="{0:C}" DisplayColumn="Freight" DataMember="Freight" />
                    </SummaryColumn>
                </ej:SummaryRow>
             </SummaryRows>
           <ClientSideEvents DataBound="dataBound" />
      <Columns>
         <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true"/>
         <ej:Column Field="CustomerID" HeaderText="Customer ID"/>
         <ej:Column Field="EmployeeID" HeaderText="Employee ID"   />
         <ej:Column Field="Freight" HeaderText="Freight" Format="{0:C}"/>
      </Columns>               
  </ej:Grid>

 

Result:

Added both top and bottom summary.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied