iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi
I am grouping grid rows and wish to use a CustomAggregate event handler to calculate a result from the grouped rows, and display that result in the group header.
My problem is that I cannot find any syntax for the GroupRowInfoText to include the custom aggregate in the group header. We have [caption], [value], [count], and the built-in aggregate functions [sum()] [avg()], [min()] and [max()]. I guess I need something like [custom].
The documentation and the example show a custom aggregate being added to a footer, but without a substitution tag - i.e. "Count =", and the aggregate value gets placed at the end. Placing the custom aggregate at the end wouldn't be as flexible as a substitution tag, but it doesn't happen in group headers.
Can you explain how to get a custom aggregate into a group header?
Thanks
Robert
Here is an outline of my workaround to show how a group value can be aggregated and included in formatted text in the group header.
The process is initiated by the InitializeRow event: grid.InitializeRow += OnInitializeRow;
grid.InitializeRow += OnInitializeRow;
The event handler picks out the rows that are group headers. In my application, there are nested groups, and the whole group hierarchy has to be processed to aggregate values; so my InitializeRow handler picks out the group headers at the top of the hierarchy:
private void OnInitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e) { WebGridRow row = e.Row; if (row.Type == RowType.GroupHeader) { if (row.Parent == null) { // this group header row is at the top of the group hierarchy PopulateGroupHeader(row); } } e.ReturnValue = true; }
The processing is done in a method that is called recursively for each level of the group hierarchy.
private void PopulateGroupHeader(WebGridRow row) { WebGridGroup group = row.GetGroup(); // Detect which group is being processed... string col = group.Column.DataMember; if (col == "outerGroupColumn") { // For nested groups, process the child groups... foreach (WebGridRow childRow in row.Children) { PopulateGroupHeader(childRow); } } else if (col == "innerGroupColumn") { // Process each row in the inner group... foreach (WebGridRow leafRow in row.Children) { if (leafRow.DataRow != null) { DataRow r = ((DataRowView)leafRow.DataRow).Row; // Access the columns in this row to form aggregated data... object datavalue = r["ColumnName"]; } } //Use the aggregated data in a formatted string and place in the group header... row.Cells[0].GroupRowInfoText = "formatted text"; }
Hello Robert,
I understand your point here, but it seems that using custom aggregate is not available for GroupRowInfoText in the group header.
The sample shows the implementation custom aggregate on a column footer. You only need to set FooterText, i.e "Count = " and set AggregateFunction to custom.
However, this is not applicable in Group header since it can be only used for built-in aggregate function only. Therefore, if you set GroupRowInfoFormat to [custom], it will display custom instead of the value being generated in custom aggregate.
Hope this helps. Thank you.
Regards,-Martin-
Hi Martin
Thanks for your confirmation that custom aggregate is not available in group headers.
I do have a workaround. Picking up each group header in an InitializeRow event handler, traversing its child rows to accumulate the aggregate result, and constructing the text using the result, I can then place the formatted text in the row's Cells[0].GroupInfoText.
Regards
Would you mind to provide us with the sample that you have successfully worked on?
Your sample would be very useful to be converted into a knowledge base, so that other user will get the benefit from your workaround sample.
Thank you.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname