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
SIGN IN To post a reply.
4 Replies
AA
Arulraj A
Syncfusion Team
January 14, 2019 10:36 AM UTC
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 08:42 PM UTC
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 16, 2019 06:23 AM UTC
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}}"
/>
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 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;
}
}
{
return value;
}
}
Thanks for the pointer.
Best regards,
Johanne
AA
Arulraj A
Syncfusion Team
January 17, 2019 05:08 AM UTC
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
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
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
-
MR MrHessellund
- Jan 13, 2019 11:29 AM UTC
- Jan 17, 2019 05:08 AM UTC