I have a Total column where I want to sum each row. I would like it to update on the client side as the footer does. I have a SummaryRow that totals the columns in the footer but I am trying to sum across each row. I have been Googling and searching the forums but have not found an example. Can someone please tell me how to do this. Do I need to use the UltraWebCalcManager? Thanks in advance.
Hello,
I have been looking into your requirements and I could suggest you handle the Client side event Initialize of our WebDataGrid and iterate through the rows in it:
for (rowindex = 0; rowindex <= rowlength - 1; rowindex++) {
currentrow = rows.get_row(rowindex);
then you can go through all of the columns in this row and sum their values. For further reference I can suggest you take a look at the following forum threads:
http://ko.infragistics.com/community/forums/p/42532/235205.aspx#235205
http://ko.infragistics.com/community/forums/t/52184.aspx
If you need any additional assistance on this please do not hesitate to ask.
Is there a working example I could see somwhere? I want the row total to update anytime a cell in that row is changed.
I have created a small sample on your behalf where I show you how you can calculate the Total on initialize and on CellChanged event.
function WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs) {
currentrow = eventArgs.getCell().get_row()
var item1 = currentrow.get_cellByColumnKey("Item1").get_value();
var item2 = currentrow.get_cellByColumnKey("Item2").get_value();
var item3 = currentrow.get_cellByColumnKey("Item3").get_value();
currentAmount = item1 + item2 + item3;
currentrow.get_cellByColumnKey("Total").set_value(currentAmount);
}
If you need any additional information on this matter please do not hesitate to ask.
Using the code you provided the control goes into an infinite loop when this is excuted. I have attached the whole page below. The code behind only sets WebDataGrid1.DataSoure and WebDataGrid1.DataBind()
Please advise. Thanks in advance.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestBed.aspx.cs" Inherits="TTFinancialProjections.TestBed" %>
<%@ Register Assembly="Infragistics35.WebUI.UltraWebCalcManager.v12.2, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.UltraWebCalcManager" TagPrefix="igcalc" %>
<%@ Register Assembly="Infragistics35.Web.v12.2, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI" TagPrefix="ig" %>
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Testbed</title>
<script type="text/javascript">
function WebDataGrid_CellEditing_ExitedEditMode(sender, eventArgs) {
currentrow = eventArgs.getCell().get_row();
var q1 = currentrow.get_cellByColumnKey("Q1").get_value();
var q2 = currentrow.get_cellByColumnKey("Q2").get_value();
var q3 = currentrow.get_cellByColumnKey("Q3").get_value();
var q4 = currentrow.get_cellByColumnKey("Q4").get_value();
currentAmount = q1 + q2 + q3 + q4;
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="false" ShowFooter="true">
<Columns>
<ig:BoundDataField DataFieldName="Id" Key="Id" />
<ig:BoundDataField DataFieldName="Name" Key="Name" Header-Text="Item" />
<ig:BoundDataField DataFieldName="Q1" Key="Q1" Header-Text="Q1" />
<ig:BoundDataField DataFieldName="Q2" Key="Q2" Header-Text="Q2" />
<ig:BoundDataField DataFieldName="Q3" Key="Q3" Header-Text="Q3" />
<ig:BoundDataField DataFieldName="Q4" Key="Q4" Header-Text="Q4" />
<ig:UnboundField Key="Total" Header-Text="Total" />
</Columns>
<Behaviors>
<ig:Activation Enabled="true" />
<ig:EditingCore BatchUpdating="true" AutoCRUD="true">
<ig:CellEditing Enabled="true" EditModeActions-EnableF2="true" EditModeActions-MouseClick="Single" CellEditingClientEvents-ExitedEditMode="WebDataGrid_CellEditing_ExitedEditMode">
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
<ig:Selection RowSelectType="Multiple" CellClickAction="Row" Enabled="true" />
<ig:SummaryRow ShowSummariesButtons="false" FormatString="{1}" AnimationType="Linear" />
<EditorProviders>
<ig:NumericEditorProvider />
</EditorProviders>
</ig:WebDataGrid>
</div>
</form>
</body>
</html>