The data is as follow
stock1 B 15
stock1 S 45
stock1 B 67
stock1 S 2
Where S-Sell and B-Buy. While grouping on column 1 (stock1) I need to display the position in stock1. But to do that while summing up the result the sell qty should be considered negative. How can I customize this sum operation?
Mitul
7 Answers, 1 is accepted
If you have a look at this help topic on Summary Rows and see the last example, this shows how to customise the summary row.
Hope that helps
Richard
I already tried that before posting the question. Here is the code that I am using. I have made one modification though where it checks whether the side has valid value or not. Although all of my rows in the gridview has side and filledqty populated after groping it throws exception if I don't put the null checking condition.
By the way the null condition occurs when I group the data by dragging exchange and product.
public class CustomSummaryItem : GridViewSummaryItem
{
public CustomSummaryItem()
: base()
{ }
public override object Evaluate(IHierarchicalRow row)
{
int totalPos = 0;
foreach (GridViewRowInfo childRow in row.ChildRows)
{
object objSide= childRow.Cells["Side"].Value;
if (objSide != null) /// if I don' know why but without this condition it throws null exception while retrieving FIlledQty.
{
if ((string)objSide == "B")
{
totalPos += (int)childRow.Cells["FilledQty"].Value;
}
else
{
totalPos -= (int)childRow.Cells["FilledQty"].Value;
}
}
}
return totalPos;
}
}
The only problem now is I have a summary row on top which shows the total correctly but as soon as the view is grouped and any of the items gets updated the main summary row total goes to 0.
public class CustomSummaryItem : GridViewSummaryItem
{
public CustomSummaryItem()
: base()
{ }
public override object Evaluate(IHierarchicalRow row)
{
int totalPos = 0;
foreach (GridViewRowInfo childRow in row.ChildRows)
{
if ((childRow is GridViewGroupRowInfo) == false)
{
object objSide = childRow.Cells["Side"].Value;
string type = Convert.ToString(childRow.Cells["ProdType"].Value);
if (type == "FUTURE")
{
if ((string)objSide == "B")
{
totalPos += (int)childRow.Cells["FilledQty"].Value;
}
else
{
totalPos -= (int)childRow.Cells["FilledQty"].Value;
}
}
}
}
return totalPos;
}
}
Thanks,
Mitul Patel
Hi.
Except for one minor bug this solution worked for me too.
I do not want the selected row in the image below to be included in the total.
For this, I adapted the solution you sent to my own project as follows.
public class CustomSummaryItem : GridViewSummaryItem
{
public CustomSummaryItem()
: base()
{ }
public override object Evaluate(IHierarchicalRow row)
{
decimal totalPos = 0;
foreach (GridViewRowInfo childRow in row.ChildRows)
{
if ((childRow is GridViewGroupRowInfo) == false)
{
string bm = childRow.Cells["bm"].Value.ToString();
if (bm != "Ä°PTAL")
{
totalPos += Convert.ToDecimal(childRow.Cells[this.Name].Value);
}
}
}
return totalPos;
}
}
As seen in the image below, the grand total row fixed to the bottom of the grid does not work as expected.
Why does this happen and how can it be fixed?
Thanks in advance for the responses.
Please open a new support ticket and send us a sample project that demonstrates the described behavior with some part of your data and grouping settings applied to RadGridView. This will allow us to investigate the issue locally.
Thank you for yout time and cooperation.
Julian Benkov
the Telerik team
Please open a new support ticket and send us a sample project that demonstrates the described behavior with some part of your data and grouping settings applied to RadGridView. This will allow us to investigate the issue locally.
Thank you for yout time and cooperation.
Nikolay
the Telerik team
Thanks,
Mitul Patel
You can find our answer in the other thread that you have opened. Please note that it has been converted to a support thread and you will not be able to find it as a forum thread. You can find it in your account after you log in.
Kind regards,Nikolay
the Telerik team