This is a migrated thread and some comments may be shown as answers.

Telerik+group footer

1 Answer 44 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
ramkumar
Top achievements
Rank 1
ramkumar asked on 17 Oct 2011, 01:11 PM
Hi telerik,

I am using RadGrid and I need to do totaling (sum) based on group.

I am using autogenerated column.

Please guid me.

my code:

 

<radG:RadGrid ID="empResults" runat="server" GridLines="Both" OnColumnCreated="RadGrid1_ColumnCreated"

 

 

Skin="Outlook" AutoGenerateColumns="true" ClientSettings-AllowDragToGroup="true" ShowGroupPanel="true"

 

 

OnGroupsChanging="RadGrid1_GroupsChanging" OnItemDataBound="RadGrid1_ItemDataBound" ShowFooter="true">

 

 

<MasterTableView AllowAutomaticUpdates="True" AllowSorting="FALSE" AllowFilteringByColumn="false"

 

 

PagerStyle-AlwaysVisible="true" ShowGroupFooter="true" ShowFooter="true" TableLayout="auto" Width="99%" >

 

 

<FilterItemStyle HorizontalAlign="left" />

 

 

<HeaderStyle ForeColor="Navy" />

 

 

<ItemStyle BackColor="White" />

 

 

<AlternatingItemStyle BackColor="#E5E5E5"/>

 

 

<Columns >

 

<%

-- <radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Time_card_no"

 

UniqueName="Time_card_no" SortExpression="Time_card_no" HeaderText="Time_Card_No">

</radG:GridBoundColumn>

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Emp_name"

UniqueName="Emp_name" SortExpression="Emp_name" HeaderText="Full_Name">

</radG:GridBoundColumn>

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Sub_project_name"

UniqueName="Sub_project_name" SortExpression="Sub_project_name" HeaderText="Sub_Project_Name">

</radG:GridBoundColumn>

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Tsdate"

UniqueName="Tsdate" SortExpression="Tsdate" HeaderText="Date">

</radG:GridBoundColumn>

 

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Inshorttime"

UniqueName="Inshorttime" SortExpression="Inshorttime" HeaderText="In_Time">

</radG:GridBoundColumn>

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Outshorttime"

UniqueName="Outshorttime" SortExpression="Outshorttime" HeaderText="Out_Time">

</radG:GridBoundColumn>

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="NH"

UniqueName="NH" SortExpression="NH" HeaderText="NH">

</radG:GridBoundColumn>

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="OT1"

UniqueName="OT1" SortExpression="OT1" HeaderText="OT1">

</radG:GridBoundColumn>

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="OT2"

UniqueName="OT2" SortExpression="OT2" HeaderText="OT2">

</radG:GridBoundColumn>

 

<radG:GridBoundColumn Display="true" ReadOnly="True" DataField="Remarks"

UniqueName="Remarks" SortExpression="Remarks" HeaderText="Remarks">

</radG:GridBoundColumn> --

 

%>

 

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

<ClientSettings Resizing-ClipCellContentOnResize="true" >

 

 

</ClientSettings>

 

 

<ExportSettings>

 

 

<Pdf PageHeight="210mm" />

 

 

</ExportSettings>

 

 

<GroupingSettings ShowUnGroupButton="false" RetainGroupFootersVisibility="true" />

 

 

</radG:RadGrid>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 18 Oct 2011, 07:40 AM
Hello RamKumar,

You can try the following in ItemDataBound event.

C#:
int total;
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
     GridDataItem dataItem = e.Item as GridDataItem;
     GridGroupByExpression exp = new GridGroupByExpression();
     GridGroupByField expfield = new GridGroupByField();
     expfield = new GridGroupByField();
     expfield.FieldName = "OrderID";
     expfield.HeaderText = "Order count ";
     expfield.Aggregate = GridAggregateFunction.Sum;
     expfield.FormatString = "({0})";
     exp.SelectFields.Add(expfield);
     expfield = new GridGroupByField();
     expfield.FieldName = "UnitPrice";
     exp.GroupByFields.Add(expfield);
     this.RadGrid1.MasterTableView.GroupByExpressions.Add(exp);
     int fieldValue = int.Parse(dataItem["OrderID"].Text);
     total += fieldValue;
  }
if (e.Item is GridGroupFooterItem)
 {
    GridGroupFooterItem itm = e.Item as GridGroupFooterItem;
    itm["OrderID"].Text = "Total :" + total.ToString();
    total = 0;
 }
}

Thanks,
Princy.
Tags
Ajax
Asked by
ramkumar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or