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

Cannot Group or Sort...

15 Answers 407 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Barry Hester
Top achievements
Rank 2
Barry Hester asked on 07 Jul 2009, 03:21 PM
Hello there...

I have a list of objects with this structure: 
Parent
Child1
Prop1
Prop2
Prop3
Child2

I can successfully bind to the grid
<tGrid:RadGridView x:Name="gridAudioContent" Grid.Row="2" Grid.Column="0"  
                           CanUserSortColumns="True"  
                           CanUserReorderColumns="True" 
                           DataLoadMode="Asynchronous" 
                           AutoGenerateColumns="False" 
                           > 
            <tGrid:RadGridView.Columns> 
                <!-- Play ////////////////////////////////////////////////////////////// --> 
                <tGrid:GridViewColumn HeaderText="Play"  UniqueName="Play" Width="Auto"
                    <tGrid:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <Button Content=">" x:Name="buttonPlay" Click="buttonPlay_Click"></Button> 
                        </DataTemplate> 
                    </tGrid:GridViewColumn.CellTemplate> 
                </tGrid:GridViewColumn> 
                <!-- Track Title //////////////////////////////////////////////////////////////// --> 
                <tGrid:GridViewDataColumn HeaderText="Title" IsFilterable="True" IsGroupable="True" UniqueName="TrackTitle" Width="Auto" DataMemberBinding="{Binding View.TrackTitle, Mode=OneTime}" IsReadOnly="True"></tGrid:GridViewDataColumn> 
                <!-- Artist ///////////////////////////////////////////////////////////////////// --> 
                <tGrid:GridViewDataColumn HeaderText="Artist" UniqueName="Artist" Width="Auto" DataMemberBinding="{Binding View.Artist, Mode=OneTime}" IsReadOnly="True"></tGrid:GridViewDataColumn> 
                <!-- Album ////////////////////////////////////////////////////////////////////// --> 
                <tGrid:GridViewDataColumn HeaderText="Album" UniqueName="Album" Width="Auto" DataMemberBinding="{Binding View.AlbumTitle, Mode=OneTime}" IsReadOnly="True"></tGrid:GridViewDataColumn> 
                <!-- Label ////////////////////////////////////////////////////////////////////// --> 
                <tGrid:GridViewDataColumn HeaderText="Label" UniqueName="Label" Width="Auto" DataMemberBinding="{Binding View.Labels, Mode=OneTime}" IsReadOnly="True"></tGrid:GridViewDataColumn> 
                <!-- Publisher ////////////////////////////////////////////////////////////////// --> 
                <tGrid:GridViewDataColumn HeaderText="Publisher" UniqueName="Publisher" Width="Auto" DataMemberBinding="{Binding View.Publishers, Mode=OneTime}" IsReadOnly="True"></tGrid:GridViewDataColumn> 
     </tGrid:GridViewColumns> 
</tGrid:RadGridView> 

In the codebehind for this page, I have this code when the data is returned from the service...
this.gridAudioContent.ItemsSource = MyCollectionOfComplexObjects; //Contains Parent objects 
this.gridAudioContent.DataContext = MyCollectionOfComplexObjects; //Contains Parent objects


However: None of the columns are groupable or sortable... I can group and sort in another grid that is bound to properties on a flat object.  Is there something I'm doing wrong, or is this behavior by design? 


15 Answers, 1 is accepted

Sort by
0
Barry Hester
Top achievements
Rank 2
answered on 08 Jul 2009, 01:43 AM
I have done a little research and here's what I've come up with:
The behavior I described: no grouping, sorting or filtering in the grid when bound to a composite object, is a "feature" of Silverlight.
An object with this structure:
  • ParentObject
  • Child Object
  • Child Property
does not play nice with grouping/sorting/filtering
When the ParentObject is used as the itemssource of a grid, you can bind to the child property like this: 
{Binding ChildObject.ChildProperty}
However, if you do this you can't group/sort/filter.  I tried this with a standard grid and saw the same behavior (sorting unavailable).

What I ended up doing is creating an object to "flatten out" the composite object:
public class Flattener : NotifyingObject // base class implements INotifyPropertyChanged 
public ParentObject Parent {getset;} 
public Flattener(ParentObject parent) 
this.Parent = parent; 
public ChildProperty 
get { return Parent.ChildObject.ChildProperty; } 
set 
Parent.ChildObject.ChildProperty = value; 
RaisePropertyChanged("ChildProperty"); 

This solved my problem, and I can now group/sort/filter in the telerik grid.  Any idea if this is something that will be addressed in 3.0?
0
Vlad
Telerik team
answered on 08 Jul 2009, 05:46 AM
Hi Barry,

The grid can sort IComparable and group/filter IEquatable<> no matter of the Silverlight version.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
joy
Top achievements
Rank 1
answered on 11 Aug 2009, 10:22 PM
Hi,

I have similar issue of lost grouping, sorting, and filtering capability once the column is binded to 2nd tier of the entitycollection.
                            <telerikGrid:GridViewDataColumn HeaderText="User" DataMemberPath="Person.Username" />
                            <telerikGrid:GridViewDataColumn HeaderText="Date" DataMemberPath="DateTimeStamp" />
                            <telerikGrid:GridViewDataColumn HeaderText="Object Name" DataMemberPath="ObjectName" />
                            <telerikGrid:GridViewDataColumn HeaderText="Comments" DataMemberPath="Comments" />
Column User cann't be grouped, sorted or filtered. And I don't think this has anything to do with what version of the silverlight.

Please help.

Joy
0
Vlad
Telerik team
answered on 12 Aug 2009, 07:29 AM
Hi Joy,

We have similar example with sub properties however everything works fine. Can you send us an example where this can be reproduced?

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
joy
Top achievements
Rank 1
answered on 12 Aug 2009, 09:04 PM
Hi,

Thanks for your example.

Instead of adding GridViewDataColumns in xaml
                    <telerikGrid:RadGridView x:Name="_gridResults" IsReadOnly="True" RowIndicatorVisibility="Visible"   AutoGenerateColumns="False" ColumnsWidthMode="Fill" CanUserFreezeColumns="True" Margin="5,0,5,5"
                                             ItemsSource="{Binding DependencyProperties.HistoryNoteList, Mode=TwoWay}">
                        <telerikGrid:RadGridView.Columns>
                            <telerikGrid:GridViewDataColumn HeaderText="User" UniqueName="Person.Username" />
                            <telerikGrid:GridViewDataColumn HeaderText="Date" UniqueName="DateTimeStamp" />
                            <telerikGrid:GridViewDataColumn HeaderText="Action" UniqueName="HistoryNoteAction.HistoryNoteAction" />
                            <telerikGrid:GridViewDataColumn HeaderText="Object" UniqueName="ApplicationLevel.ApplicationLevel" />
                            <telerikGrid:GridViewDataColumn HeaderText="Object Name" UniqueName="ObjectName" />
                            <telerikGrid:GridViewDataColumn HeaderText="Comments" UniqueName="Comments" />
                        </telerikGrid:RadGridView.Columns>
                    </telerikGrid:RadGridView>

I added all my columns in cs file, and all my columns can be grouped, sorted and filtered.

        private void AddColumnsForHistoryNotes()
        {
            this._gridResults.AutoGenerateColumns = false;
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "User", "Person.Username"));
            this._gridResults.Columns.Add(CreateColumn(typeof(DateTime), "Date", "DateTimeStamp"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Action", "HistoryNoteAction.HistoryNoteAction"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Object", "ApplicationLevel.ApplicationLevel"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Object Name", "ObjectName"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Comments", "Comments"));
        }

        private static GridViewDataColumn CreateColumn(Type columnType, string header, string dataPath)
        {
            GridViewDataColumn column = new GridViewDataColumn();
            column.DataType = columnType;
            column.UniqueName = dataPath;
            column.HeaderText = header;
            return column;
        }


The question is why can't I accomplish this through xaml? Is it because I did not set DataType in xaml? If so, what is the syntax of set DataType in xaml? FYI, my GridView ItemsSource is a ObservavleCollection.
Please explain!
Thanks,

Joy
0
joy
Top achievements
Rank 1
answered on 13 Aug 2009, 07:25 PM
Hi,

After more testing, I found all three columns(User, Action and Object), which binded to sub properties and created in cs file,  can be sorted and filtered for a couple of times after the page was loaded, after that, only grouping work on these columns, sorting and filtering were no longer work.

The other columns works fine.

Please help!

Joy
0
joy
Top achievements
Rank 1
answered on 14 Aug 2009, 05:01 PM
Hi,

Thanks for your example.

Instead of adding GridViewDataColumns in xaml
                    <telerikGrid:RadGridView x:Name="_gridResults" IsReadOnly="True" RowIndicatorVisibility="Visible"   AutoGenerateColumns="False" ColumnsWidthMode="Fill" CanUserFreezeColumns="True" Margin="5,0,5,5"
                                             ItemsSource="{Binding DependencyProperties.HistoryNoteList, Mode=TwoWay}">
                        <telerikGrid:RadGridView.Columns>
                            <telerikGrid:GridViewDataColumn HeaderText="User" UniqueName="Person.Username" />
                            <telerikGrid:GridViewDataColumn HeaderText="Date" UniqueName="DateTimeStamp" />
                            <telerikGrid:GridViewDataColumn HeaderText="Action" UniqueName="HistoryNoteAction.HistoryNoteAction" />
                            <telerikGrid:GridViewDataColumn HeaderText="Object" UniqueName="ApplicationLevel.ApplicationLevel" />
                            <telerikGrid:GridViewDataColumn HeaderText="Object Name" UniqueName="ObjectName" />
                            <telerikGrid:GridViewDataColumn HeaderText="Comments" UniqueName="Comments" />
                        </telerikGrid:RadGridView.Columns>
                    </telerikGrid:RadGridView>

I added all my columns in cs file, and all my columns can be grouped, sorted and filtered.

        private void AddColumnsForHistoryNotes()
        {
            this._gridResults.AutoGenerateColumns = false;
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "User", "Person.Username"));
            this._gridResults.Columns.Add(CreateColumn(typeof(DateTime), "Date", "DateTimeStamp"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Action", "HistoryNoteAction.HistoryNoteAction"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Object", "ApplicationLevel.ApplicationLevel"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Object Name", "ObjectName"));
            this._gridResults.Columns.Add(CreateColumn(typeof(string), "Comments", "Comments"));
        }

        private static GridViewDataColumn CreateColumn(Type columnType, string header, string dataPath)
        {
            GridViewDataColumn column = new GridViewDataColumn();
            column.DataType = columnType;
            column.UniqueName = dataPath;
            column.HeaderText = header;
            return column;
        }


The question is why can't I accomplish this through xaml? Is it because I did not set DataType in xaml? If so, what is the syntax of set DataType in xaml? FYI, my GridView ItemsSource is a ObservavleCollection.
Please explain!
Thanks,

Joy

Edit your post Reply

  • joy avatar

    Posted 19 hours ago (permalink)

    Hi,

    After more testing, I found all three columns(User, Action and Object), which binded to sub properties and created in cs file,  can be sorted and filtered for a couple of times after the page was loaded, after that, only grouping work on these columns, sorting and filtering were no longer work.

    The other columns works fine.

    Please help!

  • 0
    Nathi Mfeka
    Top achievements
    Rank 2
    answered on 27 Oct 2009, 01:31 PM
    Hi Rossi 

    I have the same problem and it really frastrating. I'm a new telerik silverlight user please advise, and post a litle demo app if you can. I'm sorry but I cant follow on the online telerik demo. here is my gridview though:
    <telerikGridView:RadGridView.Columns> 
                    <telerikGridView:GridViewDataColumn Width="50" HeaderText="ID" DataMemberPath="ID"  /> 
                    <telerikGridView:GridViewDataColumn Width="250" HeaderText="Client Name" DataMemberPath="ClientName" /> 
                    <telerikGridView:GridViewDataColumn Width="250" HeaderText="Account Manager" DataMemberPath="AccountManager.FullName"/>  
                    <telerikGridView:GridViewDataColumn Width="60" HeaderText="Archived" DataMemberPath="Archived" />    
     </telerikGridView:RadGridView> 

    I can sort fine on "ID", "ClientName" and "Archived". but I cant sort on "Account Manager", now this is happening on all the grids on my App, I think its because its linked Columns (i.e AccountManager.FullName)

    Thanks in advance.
    Nathi
    0
    Vlad
    Telerik team
    answered on 27 Oct 2009, 01:36 PM
    Hi Nathi,

    We had such issue in the past however this was fixed. Please try our latest build!

    Regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    0
    Jani
    Top achievements
    Rank 1
    answered on 30 Oct 2009, 10:11 AM
    Hi Vlad,

    Issue is still present, using the latest beta '2009_3_1019' or internal build 'Beta2_2009_3_1023'.

    Cheers,
    Jani

    0
    Vlad
    Telerik team
    answered on 30 Oct 2009, 12:33 PM
    Hello Jani,

    Can you post an example where this can be reproduced with our latest version?

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    0
    Mily
    Top achievements
    Rank 1
    answered on 02 Nov 2009, 01:27 PM
    Hi there,

    It turns out we are facing very similar problem.

    We have a collection of business objects which we then bind to a grid view.
    The business object has some properties and also has a reference to another object.
    i.e.
    public class BusinessObject
    {
            public int RowSequence { get; set; }
            public int VersionNumber { get; set; }
            public BaseConfig Config { get; set; }
    }

    Please note that the 'BaseConfig' is just the base class and the value of the Config property equals to a derived class (i.e. DeriveConfig1, DerivedConfig2). 

    The gridView is bound to the RowSequence and the VersionNumber but we also need to bind the properties of 'BaseConfig' (which are different in each derived class). We have managed to build the columns dynamically (using reflection) and set the Header, DataMemberBinding, DataType, UniqueName of each GridViewDataColumn.
    All is well until Filter is applied on the columns of the 'Config'. It throws an exception 'Invalid property or field 'Config' for type 'BaseConfig'. Investigating the problem through Reflector we found you use declared type not the runtime type to filter underlying collection:

    Telerik.Windows.Data.ItemPropertyInfoHelper :

    private static PropertyDescriptorCollection GetPropertyDescriptors(QueryableCollectionView collectionView)
    {
        return TypeDescriptor.GetProperties(collectionView.ElementType);
    }

    meaning gridView does not support the scenario we are trying to implement. Could you please confirm this is the case or if there are any workarounds / possible fix?

    Kind Regards

    Milosz / Semi

     


    0
    Stefan Dobrev
    Telerik team
    answered on 03 Nov 2009, 10:01 AM
    Hello Mily,

    You are right. We resolve property type based on the object types, so derived object properties cannot be resolved correctly. One of the workarounds you can currently implement is to create a custom view model that wraps your business object and use it for binding. The other workaround is to create a custom column for your BaseConfig type and implement the different logic for your derived types in this custom column.

    All the best,
    Stefan Dobrev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    0
    Mily
    Top achievements
    Rank 1
    answered on 05 Nov 2009, 10:07 AM
    Hi Stefan,

    Thank you for the confirmation and suggested workarounds. Are you planning to support similar scenarios in future releases?

    Kind Regards

    Milosz
    0
    Stefan Dobrev
    Telerik team
    answered on 05 Nov 2009, 05:45 PM
    Hello Mily,

    We will definitely try to handle scenarios like this in the future. Actually I have put this in our product backlog, but its priority is not very high right now. Maybe we will try to address this in post 2010 Q1 time frame.

    Best wishes,
    Stefan Dobrev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Tags
    GridView
    Asked by
    Barry Hester
    Top achievements
    Rank 2
    Answers by
    Barry Hester
    Top achievements
    Rank 2
    Vlad
    Telerik team
    joy
    Top achievements
    Rank 1
    Nathi Mfeka
    Top achievements
    Rank 2
    Jani
    Top achievements
    Rank 1
    Mily
    Top achievements
    Rank 1
    Stefan Dobrev
    Telerik team
    Share this question
    or