Home Forums WPF controls Xceed DataGrid for WPF sorting cols that use an IValueConverter

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23494 |

    In another post MiddleTommy said this;

    “I use the converters in custom cell DataTemplates for example to convert a field VenderID to the VenderName”

    I do something similar and it made me wonder… is it possible to sort a col on the *converted* value. Sorts are done using the underlying value, so any col that uses a converter (like above) will generally not sort properly.

    Imported from legacy forums. Posted by Jack (had 7019 views)

    User (Old forums)
    Member
    Post count: 23064

    /bump

    thought i’d bump this

    does anyone know a way around this, or is it a known ‘issue’?

    Imported from legacy forums. Posted by Jack (had 972 views)

    Xceed Support
    Member
    Post count: 5658

    For the moment, sorting is done on the actual value. There are plans to add a DataComparer property for version 1.2 that will allow custom sorting which should solve most issues that occur because of converted values.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 509 views)

    User (Old forums)
    Member
    Post count: 23064

    excellent, sounds like a good plan.

    thanks for the heads up

    Imported from legacy forums. Posted by Jack (had 904 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,
    I’m also very interessted in this DataComparer option.

    To support “pictured cells” I’ve switched internal cell binding
    from datatype string
    to a custom CellData-Type (with properties Text, PictureCanvasOrImage, (and an additional ToString()-converter) and “cosmetic” IconSize)
    and bound my Cells to this new datatype.

    I also replaced CellContentTemplate of the Columns with a content to display my image and my text.


    <Viewbox x:Name=”ListyPicture” Width=”{Binding Path=IconSize}” Height=”{Binding Path=IconSize}” Visibility=”Visible” Stretch=”Uniform”>
    <ContentControl Content=”{Binding Path=PictureCanvasOrImage}” >
    </ContentControl>
    </Viewbox>

    <TextBlock x:Name=”ListyTextBlock” Text=”{Binding Path=Text}” Margin=”4,0,0,0″>
    </TextBlock>

    For the moment all works fine, but sorting (by internal click on ColumnManagerCell) failed and I have no chance to fix it.

    I don’t really need a DataComparer class, I would be happy with a additional simple Column.SortBindingProperty (binding it to “[<ColIndexy>].Text”),
    but DataComparer class would also solve my issue.

    Is there any estimated completion date for release 1.2 ??

    Thanks
    Dietmar Mayer

    Imported from legacy forums. Posted by Dietmar (had 594 views)

    Xceed Support
    Member
    Post count: 5658

    Although initially planned for version 1.2, it would seem that custom sorting will not make it into the next release. Sorry to have gotten your (and mine!) hopes up.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 229 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,
    thanks for your straightforward answer.

    For my previous problem (Binding XceedGridCells to my custom ListyDataCell-Class)

    Will it be a solution, to implement any additional interface on my customnDataType e.g. IComparable with method CompareTo() ( as mentioned in http://www.codeproject.com/csharp/sortingarraylist.asp) to implement a proper sorting depended on my ListyDataCell.Text property ?

    Your CustomViews sample (Xceed.Wpf.DataGrid.Samples.ViewTheme.ZodiacCellContentTemplateSelector.cs) uses for build-in-class DateTime a custom “Cell Visual Layout”. And it sorts fine. Probably, because class DateTime sorts well ?!?

    Dietmar

    Imported from legacy forums. Posted by Dietmar (had 590 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny, Hi Folks,

    I have found the post 8466 from Marcus
    ( http://forums.xceed.com/forums/ShowPost.aspx?PostID=8466 )

    There he approved, that <b><u>IComparable</u></b>-Interface is used to sort, if available.
    I’ve implemented it for my custom ListyCellData class and sorting works now well.

    Dietmar

    Imported from legacy forums. Posted by Dietmar (had 590 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi

    I have the same problem

    I have also tried setting a series of DataGridItemProperty items in the DataGridCollectionViewSource.ItemProperties collection using both the Name and ValuePath attributes instead defining the columns directly
    Doing this causes sorting or grouping to crash

    Using only the Name attribute in conjunction with a template to display the ValuePath property (via a converter) avoids the crash but sorting will not work, and grouping treats all items as being different even when the values are the same.

    I would prefer to use the DataGridItemProperty but I can’t see that this has the ability to define the CellContentTemplate, and a generic template (on the Cell type) never gets applied.

    Also – Do I need to add code behind to make us of the IComparable technique mentioned, as it never seems to get invoked on sort?

    Thanks

    Imported from legacy forums. Posted by Nigel (had 981 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,

    what about the DataComparer property? Will it be there in version 2.0? This is a must for us. We almost allways have to apply a custom Comparer.

    Thanks
    Daniel

    Imported from legacy forums. Posted by Daniel (had 951 views)

    Xceed Support
    Member
    Post count: 5658

    I wish I could say it made the cut, but unfortunately it will not be part of version 2.0 🙁

    However, it might be possible to create a PropertyDescriptor in which the “converted” value is returned and would therefore we sorted appropriately (I am thinking in terms of IDs vs string names.. it would not be possible to implement address sorting using this setup)

    <a href=”http://forums.xceed.com/Forums/ShowPost.aspx?PostID=11343″>http://forums.xceed.com/Forums/ShowPost.aspx?PostID=11343</a&gt;

    Disclaimer: I have not tested this other than with XmlNodes so I cannot guarantee that it will give you the results you are looking for.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 449 views)

    Xceed Support
    Member
    Post count: 5658

    Forgot to say that the property descriptor should be returned by a custom DataGridItemProperty 🙂

    Imported from legacy forums. Posted by Jenny [Xceed] (had 8108 views)

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.