Welcome to the UWP feedback portal. We’re happy you’re here! If you have feedback on how to improve the UWP, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

1
Vote

With a dataset that has a DateTimeOffset column I want to bind this to a GridDateTimeColumn in an SfDataGrid  showing the date value in the local time zone with a FormatString applied to the value.

Currently through trial and error I can demonstrate that GridDateTimeColumn.FormatString only applies when neither of the ValueBinding or DisplayBinding properties are set.

  • If this is by design then the documentation should be updated to reflect this., however it is very poor design if that is the case as other toolkits do support both binding and custom formatting for dates. 

This is problematic because the GridDateTimeColumn will only show the UTC value of the DateTimeOffset even when a local timezone is defined, the accepted workaround to this is to use ValueBinding to return the value as a DateTime object explicitly set to the value that you want to render. But by doing this the FormatString is ignored. I only want to show the Date component in this interface but the time is significant so we don't want to strip the time from the value in the dataset.

The accepted solution the manually forcing a custom format when FormatString does not work is then to use ValueBinding but this casts the column type to a GridTextColumn and now the sorting and filter interface uses string logic and the string interface, instead of the expected DateFilter.

In this image you can see that when the FormatString does work, it shows the incorrect date, because it is formatting the UTC version of the value, this is not acceptable:

GridDateTimeCell Rendered.PNG


The last column, that is using the DisplayBinding solution is still not acceptable because the DateFilter options are no longer available to the user:

Empty



This is the XAML for the columns being tested:

Snippet
    <sfGrid:GridTextColumn
    ColumnSizer="Star"
    HeaderText="Raw"
    MappingName="Timestamp" />
    <sfGrid:GridDateTimeColumn 
    Width="200"
    HeaderText="Raw DateTimeOffset"
    MappingName="Timestamp"/>
    <sfGrid:GridDateTimeColumn 
    Width="200"
    HeaderText="Raw DTO Formatted"
    MappingName="Timestamp"
    FormatString="dd/MM/yyyy"/>
    <sfGrid:GridDateTimeColumn 
    Width="200"
    HeaderText="Local Date"
    MappingName="Timestamp"
    ValueBinding="{Binding Timestamp, Converter={StaticResource DateTimeValue}}"/>
    <sfGrid:GridDateTimeColumn 
    Width="200"
    HeaderText="Local Date Formatted"
    MappingName="Timestamp"
    ValueBinding="{Binding Timestamp, Converter={StaticResource DateTimeValue}}"
    FormatString="dd/MM/yyyy"/>
    <sfGrid:GridDateTimeColumn 
    Width="200"
    HeaderText="DisplayBinding"
    MappingName="Timestamp"
    ValueBinding="{Binding Timestamp, Converter={StaticResource DateTimeValue}}"
    DisplayBinding="{Binding Timestamp, Converter={StaticResource Date}}"/>

DateTimeValue is a simple converter that returns the DateTimeOffset value in the recorded timezone:


if (value is DateTimeOffset dto) return sto.DateTime;
return null;