Cannot Group or Sort...

16 posts, 0 answers
  1. Barry Hester
    Barry Hester avatar
    11 posts
    Member since:
    Feb 2005

    Posted 07 Jul 2009 Link to this post

    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? 


  2. Barry Hester
    Barry Hester avatar
    11 posts
    Member since:
    Feb 2005

    Posted 07 Jul 2009 Link to this post

    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?
  3. DevCraft banner
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Jul 2009 Link to this post

    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.
  5. joy
    joy avatar
    4 posts
    Member since:
    May 2009

    Posted 11 Aug 2009 Link to this post

    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
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Aug 2009 Link to this post

    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.
  7. joy
    joy avatar
    4 posts
    Member since:
    May 2009

    Posted 12 Aug 2009 Link to this post

    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
  8. joy
    joy avatar
    4 posts
    Member since:
    May 2009

    Posted 13 Aug 2009 Link to this post

    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
  9. joy
    joy avatar
    4 posts
    Member since:
    May 2009

    Posted 14 Aug 2009 Link to this post

    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

  10. 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!

  • Nathi Mfeka
    Nathi Mfeka avatar
    16 posts
    Member since:
    Aug 2009

    Posted 27 Oct 2009 Link to this post

    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
  • Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 Oct 2009 Link to this post

    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.
  • Jani
    Jani avatar
    61 posts
    Member since:
    Jan 2008

    Posted 30 Oct 2009 Link to this post

    Hi Vlad,

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

    Cheers,
    Jani

  • Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 Oct 2009 Link to this post

    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.
  • Mily
    Mily avatar
    15 posts
    Member since:
    Jul 2009

    Posted 02 Nov 2009 Link to this post

    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

     


  • Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 03 Nov 2009 Link to this post

    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.
  • Mily
    Mily avatar
    15 posts
    Member since:
    Jul 2009

    Posted 05 Nov 2009 Link to this post

    Hi Stefan,

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

    Kind Regards

    Milosz
  • Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 05 Nov 2009 Link to this post

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