Multiple column in summary row

4 posts, 0 answers
  1. Mick
    Mick  avatar
    5 posts
    Member since:
    Mar 2013

    Posted 17 Mar 2014 Link to this post

    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
  2. Dimitar
    Admin
    Dimitar avatar
    2654 posts

    Posted 20 Mar 2014 Link to this post

    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.

     
  3. Nisha
    Nisha avatar
    2 posts
    Member since:
    Aug 2014

    Posted 20 Aug 2014 Link to this post

    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.
  4. Dimitar
    Admin
    Dimitar avatar
    2654 posts

    Posted 22 Aug 2014 Link to this post

    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.
     
Back to Top