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

Grouping by Collection item

4 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 03 Aug 2011, 03:59 PM
Hello

I'm having a problem with grouping in the grid.
The data source is a List, the list itens contains another List, I want to group by the first item in this list (TestList[0].DescTest).
Putting the TestList[0].DescTest as DataField, the field is normally displayed, and can also be sorted, but when grouping the following error occurs:
Field definition is not valid. FieldName contains invalid characters: TestList[0].DescTest

I tried several other ways, but could not solve my problem.

public class TestInfo
{
    public int IDTest { get; set; }
     public string DescTest { get; set; }
     public List<TestInfo> TestList { get; set; }
}

<telerik:RadGrid ID="rgd_grid" runat="server" ShowGroupPanel="true" EnableHeaderContextMenu="True" EnableAJAX="True"
  OnNeedDataSource="rgd_grid_NeedDataSource">
    <ClientSettings ReorderColumnsOnClient="true" AllowGroupExpandCollapse="true" AllowDragToGroup="true" AllowColumnsReorder="true" AllowAutoScrollOnDragDrop="false" AllowExpandCollapse="false">
        <Selecting AllowRowSelect="false"/>
    </ClientSettings>
    <GroupingSettings ShowUnGroupButton="True" />
    <MasterTableView Summary="RadGrid table" Width="100%" DataKeyNames="IDTest" Name="Test">
        <Columns>
            <telerik:GridBoundColumn UniqueName="IDTest" DataField="IDTest" HeaderText="IDTest" Groupable="True">
                </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="DescTest" DataField="DescTest" HeaderText="DescTest" Groupable="True">
                </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="GroupTest" DataField="TestList[0].DescTest" HeaderText="GroupTest" Groupable="True">
                </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

private List<TestInfo> CreateDataSource()
{
    List<TestInfo> list = new List<TestInfo>();
 
    list.Add(new TestInfo());
    list[0].IDTest = 1;
    list[0].DescTest = "Test 1";
    list[0].TestList = new List<TestInfo>();
    list[0].TestList.Add(new TestInfo());
    list[0].TestList[0].DescTest = "Group 1";
 
    list.Add(new TestInfo());
    list[1].IDTest = 2;
    list[1].DescTest = "Test 2";
    list[1].TestList = new List<TestInfo>();
    list[1].TestList.Add(new TestInfo());
    list[1].TestList[0].DescTest = "Group 2";
 
    list.Add(new TestInfo());
    list[2].IDTest = 3;
    list[2].DescTest = "Test 3";
    list[2].TestList = new List<TestInfo>();
    list[2].TestList.Add(new TestInfo());
    list[2].TestList[0].DescTest = "Group 3";
 
    return list;
}
 
protected void rgd_grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    rgd_grid.DataSource = CreateDataSource();
}

4 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 09 Aug 2011, 01:47 PM
I could not solve my problem. Has anyone had the same situation?
0
Veli
Telerik team
answered on 12 Aug 2011, 07:43 AM
Hello Milak The,

Grouping by nested or indexed properties is not supported in RadGrid. You need to map your nested property to a first level property in your data class:

public class TestInfo
{
    public int IDTest { get; set; }
    public string DescTest { get; set; }
    public List<TestInfo> TestList { get; set; }
     
    //property maps the first TestList item description
    public string FirstChildDesc
    {
        get
        {
            if (TestList != null && TestList.Count > 0)
            {
                return TestList[0].DescTest;
            }
             
            return String.Empty;
        }
    }
}

Now you can specify FirstChildDesc for grouping in RadGrid.

Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Peter From LA
Top achievements
Rank 1
answered on 16 Oct 2012, 10:41 PM
Hi, Veli,

Is this still the case a year later?
I have the same problem, and was wondering how am I going to create dynamically all the first level propties to accomodate my dynamic list of properties.
There is no way I can tell the clients not to group by their dynamic custom properties...  :(

P
0
Vasil
Telerik team
answered on 19 Oct 2012, 02:11 PM
Hello Peter,

The Grid still can group only by first level properties.
You could try Greg's suggestions in this forum: http://stackoverflow.com/questions/799022/net-reflection-create-class-properties to create dynamically class with all the properties.


Regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Veli
Telerik team
Peter From LA
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or