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
Is there a way set some column ( for example columnC ) footer value is sum(columnA)/sum(columnB) by useing CustomAggregate function?
Thanks
You could modify the snippet so instead of iterating e.Rows you will iterate the WebGrid datasource or you will need to requery the data if the WebGrid do not cache the data.
Here is the updated snippet that will iterate the WebGrid datasource, in my scenario the DataSource is a DataTable:
protected void wgTest_CustomAggregate(object sender, ISNet.WebUI.WebGrid.CustomAggregateArgs e){ if (e.Column.DataMember == "Date") { DataTable dtSource = (DataTable)wgTest.GetCachedDataSource(); Double sumVal = 0; Double sumValX = 0; for (int i = 0; i < dtSource.Rows.Count; i++) { sumVal += (Double)dtSource.Rows[i]["Value"]; sumValX += (Double)dtSource.Rows[i]["ValueX"]; } e.AggregateResult = sumValX + " / " + sumVal + " : " + ((Double)(sumValX / sumVal)).ToString("#.#0"); }}
CustomAggegrate function has already support this scenario. For example if you wish to calculate the sum[ValueX] / sum[Value] on the column Date. Here is the snippet:
protected void wgTest_CustomAggregate(object sender, ISNet.WebUI.WebGrid.CustomAggregateArgs e){ if (e.Column.DataMember == "Date") { WebGridRowCollection rows = e.Rows; Double sumVal = 0; Double sumValX = 0; for (int i = 0; i < rows.Count; i++) { WebGridCell cellVal = rows[i].Cells.GetNamedItem("Value"); sumVal += (Double)cellVal.Value; WebGridCell cellValX = rows[i].Cells.GetNamedItem("ValueX"); sumValX += (Double)cellValX.Value; } e.AggregateResult = ((Double)(sumValX / sumVal)).ToString("#.#0"); }}
In this example both the Value and ValueX column has a Double datatype.
You could read the CustomAggegrate walkthrough in or WebGrid documentation under the article "Walkthrough: Using Custom Aggregate function in WebGrid"
Thanks a lot, If webgrid in SelfReferencing mode and ColumnFooterAggregateMode="CalculateAllData", how to use CustomAggregate API calculate all data? this example only calculate the level 1 rows. not all data.
Best Regards
I try to using the snippet code, but GetCachedDataSource() function always return null, (AllowAutoDataCaching=True, AlwaysUseCachedDataOnFirstLoad=False). How can i do?
Thank you, I make a mistake, so GetCachedDataSource() return is null, now it can work, thanks again
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