Ticket Q579080
Visible to All Users

ASPxGridView - How to show grouped row count summary in group row instead of actual child row counts

created 11 years ago

I have a requirement which is a little different than most summaries for grouped rows. When you use Count, you want what DevExpress gives out of the box: the number of actual records (nor grid rows) inside the group.

I need to count the number of DISTINCT records considering the grouped column whithin the group. I believe I could achive it by counting number of of grouped grid rows, not actual records within a group. Le me explain:

I've got the following columns: Name, City, DateVisited

I'm grouping by City, then Name… I would like to count how many distinct persons visited a city, not the count of how many visits in total there were.

Example:

Felipe, New York, 1/1/2010
Felipe, New York, 1/1/2011
Felipe, Rio, 1/1/2013
Julio, Rio, 1/1/2014
Felipe, Rio, 1/1/2014

If I group by city I would have:

  • New York (count = 2)
    -- Felipe, New York, 1/1/2010
    -- Felipe, New York, 1/1/2011
  • Rio (count = 3)
    -- Felipe, Rio, 1/1/2013
    -- Julio, Rio, 1/1/2014
    -- Felipe, Rio, 1/1/2014

That's perfectly fine… but when I group by City, then Person, I got this:

  • New York (count = 2)
    -+ Felipe (count = 2)
  • Rio (count = 3)
    -+ Felipe (count = 2)
    -+ Julio (count = 1)

What I'm trying to do is this:

  • New York (count = 1)
    -+ Felipe (count = 2)
  • Rio (count = 2)
    -+ Felipe (count = 2)
    -+ Julio (count = 1)

In other words, the "city" group count is only counting the number of grouped rows immediately beneath it…

I don't know if that is the best approach… What I'm trying to do is to reuse the main grid of the application to allow the end-user to seamlessly get the most important data for them which is the count of individual persons that visited a city (actually it is the number of employees that went to a customer within a timeframe).

Is there a way to show the count of grouped rows in a group header?

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello Felipe,
Yes, it is possible. Handle the CustomGroupDisplayText event to count child rows using the GetChildRowCount method and display it in the group's text.
Updated:
Alternatively, add the group summary:

ASPx
<GroupSummary> <dx:ASPxSummaryItem SummaryType="Count" FieldName="Name" ShowInColumn="Name" /> </GroupSummary>
    Show previous comments (5)
    Anthony (DevExpress Support) 11 years ago

      In fact, this is a limitation of server mode. It returns only a portion of data that is necessary to display on the current page. Thus, there's no data in the grid to work with in the GetChildRowCount method, that is why it returns "1" until you expand the group and the data is obtained to be shown in the group. It is possible to force the group expansion in code, but in this case, the sole purpose of server mode will be lost: there might be hundreds of thousands of child rows in groups.
      The only possible solution I see here is to manually query the datasource based on the currently processed group text in the CustomGroupDisplayText event. A similar approach is used in the Custom Binding demo (MVC GridView => Model (GridViewCustomBindingModel) => GetSummaryValuesAdvanced). The currently applied grouping state and filter expression should be taken into account to return correct results.

        Anthony, thanks for the pointers! I'll CERTAINLY implement this functionality as you suggested. Since I was in a hurry, for now I've just made a compromise to ask the end user to expand the first-level grouping if the wants an up-to-date count of visits. I've told it was a limitation on our backend server to keep the performance of the whole system at an acceptable level (which is true!). I'll work on the implementation using the current group text soon… When it is finished I'll provide the complete solution here to share it with other users.

        Anthony (DevExpress Support) 11 years ago

          We will be waiting for your response then.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.