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

Grouping and Sorting

7 Answers 237 Views
GridView
This is a migrated thread and some comments may be shown as answers.
KMBah
Top achievements
Rank 1
KMBah asked on 25 Mar 2008, 04:22 PM
I am having a problem grouping by a certain column and ordering by a different column. When I group by a column it puts them in alphabetical order. I want the rows in a different order. For example...

I'm using XML similar to this to populate the gridview...
<?xml version="1.0" encoding="UTF-8"?>  
<RootElement xmlns:mstns="http://tempuri.org/RootElement.xsd">  
    <System> 
        <ID>681F04EF-80CD-47FE-AC8C-5DC497E2BDCD</ID> 
        <Name>String</Name> 
        <Owner>String</Owner> 
        <Services>String</Services> 
        <SystemType>Beta</SystemType> 
        <OrderNum>1</OrderNum> 
        <DateLastModified>2001-12-17T09:30:47.0Z</DateLastModified> 
    </System> 
    <System> 
        <ID>CCA76E63-B4B5-4AA4-A5BD-E8A1D83A0C91</ID> 
        <Name>String</Name> 
        <Owner>String</Owner> 
        <Services>String</Services> 
        <SystemType>Zeta</SystemType> 
        <OrderNum>2</OrderNum> 
        <DateLastModified>2001-12-17T09:30:47.0Z</DateLastModified> 
    </System> 
    <System> 
        <ID>CCA76E63-B4B5-4AA4-A5BD-E8A1D83A0C91</ID> 
        <Name>String</Name> 
        <Owner>String</Owner> 
        <Services>String</Services> 
        <SystemType>Alpha</SystemType> 
        <OrderNum>3</OrderNum> 
        <DateLastModified>2001-12-17T09:30:47.0Z</DateLastModified> 
    </System> 
    <System> 
        <ID>CCA76E63-B4B5-4AA4-A5BD-E8A1D83A0C91</ID> 
        <Name>String</Name> 
        <Owner>String</Owner> 
        <Services>String</Services> 
        <SystemType>Kappa</SystemType> 
        <OrderNum>4</OrderNum> 
        <DateLastModified>2001-12-17T09:30:47.0Z</DateLastModified> 
    </System> 
</RootElement> 

I'm using the OrderNum as a way to determine which order I want them showing up in the gridview. So I want to see the list like this...

Beta
    (All of the rows that fall into the Beta group)
Zeta
    (All of the rows that fall into the Zeta group)
Alpha
    (All of the rows that fall into the Alpha group)
Kappa
    (All of the rows that fall into the Kappa group)

If I don't use OrderNum at all I get...
Alpha
    (All of the rows that fall into the Alpha group)
Beta
    (All of the rows that fall into the Beta group)
Kappa
    (All of the rows that fall into the Kappa group)
Zeta
    (All of the rows that fall into the Zeta group)

Obviously it's defaulting to alphabetical order.

If I use  "OrderNum format '{1}. ', SystemType format '{1}' Group By OrderNum I get

1. 
    (All of the rows that fall into the Beta group)
2. 
    (All of the rows that fall into the Zeta group)
etc...

I want to see

1. Beta
    (All of the rows that fall into the Beta group)
2. Zeta
    (All of the rows that fall into the Zeta group)
etc...

or

Beta
    (All of the rows that fall into the Beta group)
Zeta
    (All of the rows that fall into the Zeta group)
etc...

Sorry for the length, but I wanted to make sure you all had all the information you might need to help me out.

Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 25 Mar 2008, 05:38 PM
Hello Ken,

There are restrictions on the columns that are allowed in the expression before the "Group By":
  • Columns which you group by.
  • Aggregates on whichever columns.
In the expression you provide, the value of SystemType is required, but it is not obvious for the RadGridView that the same value is set for all records in a group. That is why it is disregarded. What you can do is use an aggregate:

'OrderNum format '{1}.', first(SystemType) format '{1}' Group By OrderNum

Obviously, if you have different values for SystemType, the value from the first row in the group will be respected.

I hope you find this information useful. If you have more questions drop me a line. I will be happy to assist you.

All the best,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
KMBah
Top achievements
Rank 1
answered on 25 Mar 2008, 06:47 PM
Thank you very much for your quick response. I tried that exact syntax in the groupbyexpression and got an error stating "System.FormatException: Input string was not in a correct format".

Troubleshooting a bit it seems it does not like the "first(SystemType)" part. For the aggregate, does it not need to be a number? SystemType has values such as Alpha, Beta, Kappa, Zeta. Can you put a "first()" around those values?

Another thought is whether I can group by both ordernum and systemtype and then hide the ordernum group header row. Is this possible?

Thanks again
0
Dwight
Telerik team
answered on 26 Mar 2008, 09:00 AM
Hello Ken,

Let me elaborate a bit on our implementation of aggregates. Three groups may be distinguished:
  • Data types that support aggregations (sum, difference, multiplication, etc.). Applicable for those types are AVG, SUM, etc.
  • Data types that support comparison (for example, the string data type). Applicable aggregates are MIN and MAX.
  • All other types. The aggregates available are FIRST and LAST. Those respect the position of the record (row) in the group rather than the actual value of the respective field.
The second solution you propose actually matches the concept of our group-by expressions. What I mean is that one group-by expression (no matter how many fields are placed after the Group By clause) should create a single grouping level. Currently, it generates N levels and we plan to address that.

Hiding the group-by header rows is currently not possible.

If you have any other questions, please contact me again.

Kind regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
KMBah
Top achievements
Rank 1
answered on 26 Mar 2008, 03:42 PM
Thank you again for your response. That helps explain the aggregates better.

I found a way to hide the headers for the initial groupings. It leaves a gap, but I am working on minimizing that effect or ignoring it all together.

for (int i = 0; i < radGridView.GridElement.GridViewInfo.Rows.Count; i++)
    radGridView.GridElement.GridViewInfo.Rows[i].VisualElement.Visibility =
ElementVisibility.Hidden;

If this is not a viable fix for some reason that I can't see please let me know.

Thanks

0
Jack
Telerik team
answered on 28 Mar 2008, 05:44 PM
Hi Ken,

Currently, the hiding of group header rows is not supported.

The code you attached will not work. This is due to the virtualization used in the RadGridView. RadGridView creates visual elements only for the rows that are currently visible on the screen. They are reused when the RadGridView is scrolled or resized, which improves performance and minimizes memory usage.

You should never work with the visual elements directly, as they are reused and they are used to display different records at different times due to scrolling operations. Use the logical rows inside the Rows collection instead.

Do not hesitate to contact me, if you have other questions.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Finn
Top achievements
Rank 1
answered on 25 Jul 2008, 08:31 PM
OK, so how does one hide the group header rows when one has expanded all groups?

Finn
0
Jack
Telerik team
answered on 28 Jul 2008, 11:56 AM
Hello Finn,

Thank you for getting back to me.

It is not possible to hide only the group header rows and to show only data rows when all groups are expanded. An alternative solution is to remove grouping in this case. We will consider implementing this scenario in a future version of RadControls.

You can hide header rows by using the code below, but this will hide also all child rows for the group:

foreach (DataGroup group in this.radGridView1.Groups) 
    group.HeaderRow.IsVisible = false

I hope this helps. Please let me know if you need further assistance.

Regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
KMBah
Top achievements
Rank 1
Answers by
Dwight
Telerik team
KMBah
Top achievements
Rank 1
Jack
Telerik team
Finn
Top achievements
Rank 1
Share this question
or