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

Multiple column in summary row

3 Answers 421 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mick
Top achievements
Rank 1
Mick asked on 17 Mar 2014, 07:58 PM
I have a grid that shows sports statistics for each player for each game. Using basketball as an example, column 1 will have the players names and after that will come FGA (field goal attempts), FG (number of field goals made), FTA (free throw attempts), FT (number of free throws made), TP (total points), etc. There might be as many as 20 columns and the column names change based on the sport and position. At the bottom of the grid in column 1 is "Game Totals". The other columns have a sum or an average of all the players in the game. We get the list of columns using a query into a datatable. How do I get this variable list of columns into the summary row?
Thank you,
Mick Mathews

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 20 Mar 2014, 12:54 PM
Hello Mick,

Thank you for writing.

If I understand correctly, you want your summary row to display a summary for each of your columns. This can be done by just adding the corresponding GridViewSummaryItem objects to the summary row item. For example:
GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "FGA";
summaryItem.Aggregate = GridAggregateFunction.Avg;
 
GridViewSummaryItem summaryItem1 = new GridViewSummaryItem();
summaryItem1.Name = "FTA";
summaryItem1.Aggregate = GridAggregateFunction.Avg;
 
GridViewSummaryItem summaryItem2 = new GridViewSummaryItem();
summaryItem2.Name = "TP";
summaryItem2.Aggregate = GridAggregateFunction.Avg;
 
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);
summaryRowItem.Add(summaryItem1);
summaryRowItem.Add(summaryItem2);
 
this.radGridView1.SummaryRowsTop.Add(summaryRowItem);

If you want to customize the summary row you can check the following help article: Summary Rows. If you want something else, please specify your exact goals one more time (maybe I am missing something). Perhaps you can give an example of how exactly the desired summary row should look. 

I hope this helps.

Regards,
Dimitar
Telerik

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Nisha
Top achievements
Rank 1
answered on 20 Aug 2014, 02:25 PM
Hi Dimitar,

Adding to this post, I have a grid which has a large number of columns and column names can differ based on different user roles.Is there any way that we can generically loop through all the columns and have a Summary Row instead of writing lines of code for each hard-coded Column Names.
0
Dimitar
Telerik team
answered on 22 Aug 2014, 12:32 PM
Hi Nisha,

Thank you for writing.

You can iterate through the columns and add the summary row like this:
void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
    for (int i = 0; i < radGridView1.Columns.Count; i++)
    {
        GridViewSummaryItem summaryItem = new GridViewSummaryItem();
         
        summaryItem.Name = radGridView1.Columns[i].Name;
        if (radGridView1.Columns[0] is GridViewDecimalColumn)
        {
            summaryItem.Aggregate = GridAggregateFunction.Sum;
        }
        else
        {
            summaryItem.Aggregate = GridAggregateFunction.Count;
        }
         
         
        summaryRowItem.Add(summaryItem);
    }
     
    radGridView1.SummaryRowsBottom.Add(summaryRowItem);
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Mick
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Nisha
Top achievements
Rank 1
Share this question
or