We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to create a Binding of Custompattern in TreeGridDateTimeColumn

Hi,

Trying to do this:

<syncfusion:TreeGridDateTimeColumn MappingName="Date" HorizontalHeaderContentAlignment="Left" ColumnSizer="AutoFillColumn" AllowNullValue="True" AllowEditing="True" CanEdit="True" Pattern="CustomPattern" CustomPattern="{Binding Path=DateFormat}" />

Whereas Date and DateFormat are both Properties of the ItemsSource used by the SfTreeGrid.

However, the DateFormat seems not to apply.

Goal is to be able to have per cell CustomPattern in the DateTimeColumn.

What am I missing?

Please advise.

Best regards,
Johannes

4 Replies

AA Arulraj A Syncfusion Team January 14, 2019 02:36 AM

Hi Johannes, 
 
Thank you for contacting Syncfusion support. 
 
We have analyzed your query and you can achieve your requirement by setting the CustomPattern to the GridDataTimeColumn by using the below code snippets. 
 
Solution 1:  
Bind the DateFormats from ViewModel by using the below code snippets. 
 
<syncfusion:TreeGridDateTimeColumn MappingName="DOB" TextAlignment="Right"  
                                    HorizontalHeaderContentAlignment="Left" 
                                    ColumnSizer="AutoFillColumn"  
                                    AllowNullValue="True"  
                                    AllowEditing="True" CanEdit="True" 
                                    CustomPattern="{Binding Pattern}" Pattern="CustomPattern" /> 
 
 
Solution 2: 
Bind the DateFormats from Model ie (RowData) by using the below code snippets. 
<syncfusion:TreeGridDateTimeColumn MappingName="DOB"  
                                    HeaderText="DOB WITH ROWDATA" 
                                    TextAlignment="Right"  
                                    HorizontalHeaderContentAlignment="Left" 
                                    ColumnSizer="AutoFillColumn"  
                                    AllowNullValue="True"  
                                    AllowEditing="True" CanEdit="True" 
                                    CustomPattern="{Binding Converter={StaticResource converter}}" Pattern="CustomPattern" /> 
 
Converter codes: 
class Converter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        var employee = value as Employee; 
        if (employee != null) 
        { 
            return employee.Pattern; 
        } 
        else 
            return ""; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        return value; 
    } 
} 
 
Please find the Sample from the below location. 

Arulraj A 



MR MrHessellund January 14, 2019 12:42 PM

Hi,

Thank you for this.

It seems the best option should be to go with the converter, in order to get pattern per cell.

However, the DOB WITH ROWDATA does not work on my setup.

In

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        var employee = value as Employee; 
        if (employee != null) 
        { 
            return employee.Pattern; 
        } 
        else 
            return ""; 
    }

"value" seems to be the viewmodel/datacontext, and not the specific Employee object of the relevant row.

I am testing with latest Syncfusion essential studio 2018 vol 4.

Please advise.
Best regards


MR MrHessellund January 15, 2019 10:23 PM

Hi,

Figured it out.

In XAML did this:

<syncfusion:TreeGridDateTimeColumn MappingName="DOB"
                                                HeaderText="DOB WITH ROWDATA"
                                                TextAlignment="Right"
                                                HorizontalHeaderContentAlignment="Left"
                                                ColumnSizer="AutoFillColumn"
                                                AllowNullValue="True"
                                                AllowEditing="True" CanEdit="True"
                                               DisplayBinding="{Binding Converter={StaticResource converter}}"
                                                 />

In converter:

class Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var employee = value as Employee;
            if (employee != null)
            {
                if (employee.DOB != null)
                    return employee.DOB.Value.ToString(employee.Pattern);
                return "Undated";
            }
            else
                return "";
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }


Thanks for the pointer.

Best regards,
Johanne


AA Arulraj A Syncfusion Team January 16, 2019 09:08 PM

Hi Johanne,

Thanks for the update.

Please feel free to contact us in case of any further difficulty. We'll be glad to assist you.

Regards,
Arulraj A

Loader.
Live Chat Icon For mobile
Up arrow icon