Hi!
I have date values in my LocalDataSourceProvider and in the filter dialog I want to display only years as values. What I get is:
a) all date values
b) date values with "00:00:00" time added
c) dates with the wrong locale although I set the right culture on my LocalDataSourceProvider (this shoud be German date like "dd.MM.yyy")
What I like to have is a filter dialog showing only "2017, 2018, 2019, 2020, 2021, ..."
Besides that: the filter dialog is much too small if you have a filter condition "between" and two date values, see screenshot.
Regards
Heiko
4 Answers, 1 is accepted
Hello Heiko,
I will check this and see if I can suggest anything useful for the described scenario.
Regards,
Martin Ivanov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hello Heiko,
The list with items shown in the dialog reflects all distinct date values in the data source. If you want to show only years, I would suggest you to use only DateTimeGroupDescription with its Step set to Year. Compared to the PropertyGroupDescription used when the full date is shown. If you use the RadPrivotFieldList to filter the dates, you can leave only the Year option and disable the others. To do so, you can use an implicit style that targets the TreeGridRowHeader element and set its Visibility with an IValueConverter.
<pivot:RadPivotFieldList.Resources>
<local:FieldToVisibilityConverter x:Key="FieldToVisibilityConverter" />
<Style TargetType="pivot:TreeGridRowHeader">
<Setter Property="Visibility" Value="{Binding Data, Converter={StaticResource FieldToVisibilityConverter}}" />
</Style>
</pivot:RadPivotFieldList.Resources>
public class FieldToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var field = value as Field;
if (field != null && field.FieldInfo != null)
{
if (field.FieldInfo is DateTimePropertyFieldInfo &&
((DateTimePropertyFieldInfo)field.FieldInfo).DateTimeStep != Telerik.Pivot.Core.DateTimeStep.Year)
{
return Visibility.Collapsed;
}
else if (!(field.FieldInfo is DateTimePropertyFieldInfo) && field.FieldInfo.DataType == typeof(DateTime))
{
return Visibility.Collapsed;
}
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
About the small dialog, you can resize it by the window's corners during run-time execution. Or if you want to change its size programmatically, you can use the RoutedDialogEvents.RequestDialog event.
public MainWindow()
{
InitializeComponent();
pivotFieldList.AddHandler(RoutedDialogEvents.RequestDialog,
new EventHandler<DialogHostingRequestEventArgs>(this.OnDialogHostRequested), true);
}
private void OnDialogHostRequested(object sender, DialogHostingRequestEventArgs e)
{
var labelDialog = e.DialogInfo.Content as LabelFilterDialog;
if (labelDialog != null)
{
var w = labelDialog.ParentOfType<RadWindow>();
w.Width = 500;
}
}
For the format of the dates, you can use the RoutedDialogEvents.RequestDialog event again, but to replace the default DataTemplate used for the CheckBox content and apply the desired format. For example:
private void OnDialogHostRequested(object sender, DialogHostingRequestEventArgs e)
{
var labelDialog = e.DialogInfo.Content as LabelFilterDialog;
if (labelDialog != null)
{
var itemsControl = labelDialog.FindChildByType<ItemsControl>();
itemsControl.ItemTemplate = (DataTemplate)this.Resources["CustomLabelFilterDialogItemTemplate"];
}
}
<UserControl.Resources>
<local:SelectableToStringConverter x:Key="SelectableToStringConverter" />
<DataTemplate x:Key="CustomLabelFilterDialogItemTemplate">
<CheckBox Content="{Binding Converter={StaticResource SelectableToStringConverter}}" Margin="5"
IsChecked="{Binding IsSelected, Mode=TwoWay, FallbackValue={x:Null}}" />
</DataTemplate>
</UserControl.Resources>
public class SelectableToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var selectable = value as Selectable;
if (selectable != null && selectable.Item is DateTime)
{
var item = (DateTime)selectable.Item;
return item.Date.ToString("dd.MM.yyy", CultureInfo.GetCultureInfo("de-DE"));
}
else if (value is INamed)
{
return ((INamed)value).DisplayName;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
I hope this information helps.
Regards,
Martin Ivanov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Hello Martin,
Thank you for your detailed answer, I really appreciate that.
For the first part, FieldToVisibilityConverter: this is throwing an exception saying "NaN is not a valid value for property Value". I will take a look at it again and debug it.
The second and third part, OnDialogHostRequested: I had to change the type of e.DialogInfo.Content to ItemsSetFilterDialog, now it is working as expected. However, with regard to these two points, I see Telerik obliged to change this in PivotGrid. It's a good workaround, but the lack of date formatting and the too small size of a dialog box are actually bugs that need to be fixed.
Regards
Heiko
Hello Heiko,
Indeed, the solutions may need slight adjustments because the data types can vary in some cases. Anyway, I am glad that this was useful.
As for your feedback, I've logged a couple of items in our feedback portal where you can track their status.
Regards,
Martin Ivanov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.