dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] WPF - XAML - XamDataGrid - How to sort by Date Field?

  1. #1

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Resolved [RESOLVED] WPF - XAML - XamDataGrid - How to sort by Date Field?

    Code:
    <Custom:XamDataGrid.FieldLayouts>
    <Custom:FieldLayout Key="masterRow">
        <Custom:FieldLayout.SortedFields>
            <Custom:FieldSortDescription Direction="Ascending" FieldName="ClosingDate"/>
        </Custom:FieldLayout.SortedFields>
         ...
    I'm sorting by some fields correctly, by doing this the user can simply click the Column header and the column is sorted. The problem appears with date fields, it's using the date as a string for sorting, like:

    01/09/2013
    02/02/2012
    04/12/2013
    05/01/2012
    ...

    So, is there any way to use a formatted date value for sorting (like format "YYYYMMDD"), or maybe using a converter and applying it into XAML? What's the best solution for this problem?

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,010

    Re: WPF - XAML - XamDataGrid - How to sort by Date Field?

    How are you sorting? Mine works but my format is

    Code:
    <GridViewColumn DisplayMemberBinding=
                                "{Binding Path=ExpDate, StringFormat='MMM. dd, yyyy'}" 
                                Header="Exp. Date" Width="110"/>
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: WPF - XAML - XamDataGrid - How to sort by Date Field?

    Hey dee-u. Actually i'm not Binding or applying format because i didn't want to affect how the date is being displayed i want to keep showing format "DD/MM/YYYY" but i want sorting to sort correctly according to date (the format needed for this would be "YYYYMMDD"), is this possible using your code? Showing a date format but sort using another?
    This grid comes with Infragistics.

    EDIT:

    It's resolved now, i had to use EditAsType using type Datetime. For some reason this field was formatted as String and that's why it was being sorted by the grid like a String.
    Last edited by jcis; Jan 29th, 2014 at 08:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width