When deriving and creating a custom date column, what is required in order to maintain sorting and filtering? Here is the original question, posted under a different question already answered:
"When you do this, what is required in order to maintain sorting and filtering capabilities for dateTime?
If you derive a column from DateColumn and and Provider from DateColumnContentProvider and use even a standard datepicker binding in ResolveDisplayElement and return the datePicker in ResolveEditorControl, the sorting seems to be broken and the filtering for specialized filters for things like contains, and not equals appears to be broken as well.
What is the approach one is supposed to take for implementing this custom dateColumn so that things like sorting and filtering stay intact?"
original reference:http://community.infragistics.com/forums/p/56173/347406.aspx#347406
Thanks,
__________________________________________
I have noticed in an upcoming release a new date time column:
http://blogs.infragistics.com/blogs/atanas_dyulgerov/archive/2012/04/25/new-datetimecolumn-for-the-infragistics-xamgrid-in-2012-1.aspx
And hopefully this will solve issues regarding many customizations currently needed to achieve similar features that the new column type will offer.
Thanks Elena and Team. This sample shows very clearly how easy it is to use custom columns and properly bind them.
Hello Don,
Thank you for the snippets. I have been researching over this approach and I have consult with our engineering team on this matter and I believe that the issue that you are referring is caused because of the bindings that you perform in ResolveDispalyElement method.
Please find the attached sample where we made some modification in CustomDateColumn in order to bind the value displayed in the editor to the actual cell values.
If you have any additional questions or concerns on this matter, please feel free to ask.
Hi Elena,
If thats the case then perhaps this is a trivial issue and some technical error on my implementation. Here is a quick sample:
Custom Column Class using nullable dateTime? :
public class CustomDateColumn : DateColumn { protected override ColumnContentProviderBase GenerateContentProvider() { return new DateTimeColumnContentProvider(); } public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(DateTime?), typeof(CustomDateColumn), new PropertyMetadata( new PropertyChangedCallback(ContentChanged))); public DateTime? Content { get { return (DateTime?)this.GetValue(ContentProperty); } set { this.SetValue(ContentProperty, value); } } private static void ContentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { CustomDateColumn col = (CustomDateColumn)obj; col.OnPropertyChanged("Content"); } public static readonly DependencyProperty ContentBindingProperty = DependencyProperty.Register("ContentBinding", typeof(Binding), typeof(CustomDateColumn), new PropertyMetadata( new PropertyChangedCallback(ContentBindingChanged))); public Binding ContentBinding { get { return (Binding)this.GetValue(ContentBindingProperty); } set { this.SetValue(ContentBindingProperty, value); } } private static void ContentBindingChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { CustomDateColumn col = (CustomDateColumn)obj; col.OnPropertyChanged("ContentBinding"); } }
Column Provider Class using CustomDateColumn:
As far as I know you must override 'ResolveDisplayElement' in order to utilize your
own control for display purposes. In this case I just used a datePicker. I have tried binding to other
properties but it hasn't seemed to affect the outcome for sorting, which fails to sort properly.
public class DateTimeColumnContentProvider : DateColumnContentProvider { Cell _cell; CustomDateColumn _column; DatePicker _dtPicker; public DateTimeColumnContentProvider() { _dtPicker = new DatePicker(); } public override FrameworkElement ResolveDisplayElement(Cell cell, System.Windows.Data.Binding cellBinding) { _column = (CustomDateColumn)cell.Column; Binding binding = new Binding(_column.Key); if (_column.Content == null) { binding.Mode = BindingMode.OneWay; if (_column.ContentBinding != null) { this._dtPicker.SetBinding(DatePicker.TextProperty, _column.ContentBinding); } else { this._dtPicker.SetBinding(DatePicker.TextProperty, binding); } } else { binding = new Binding("Text"); binding.Source = _column; this._dtPicker.SetBinding(DatePicker.TextProperty, binding); } return _dtPicker; } public override void AdjustDisplayElement(Infragistics.Controls.Grids.Cell cell) { this._cell = cell; base.AdjustDisplayElement(cell); } public override object ApplyFormatting(object value, Column column, System.Globalization.CultureInfo culture) { return base.ApplyFormatting(value, column, culture); } }
I have been researching the issue and currently we implement the filtering and the sorting based of the properties from your model which provides the cell data. Therefore when you enter some filter value it will sort the column comparing all of the values of the cells to this filter, no matter what is your display element and how you retemplate the cells content elements. All this said I believe that the filtering and the sorting functionality should be preserved when you derive from DateColumn.
Based on this the issue that you are referring may be due to the internal type of data that you use. Would you please make sure that you provide data from type DateTime to this particular column.
If this is not your case would you provide me with small test sample where this approach is representable so I can be sure that we are looking on the same functionality.
Thanks in advance.
My issue is that deriving and maintaining functionality for custom columns is broken and should be fixed. What is the point in deriving from a dateColumn (for example) if the functionality its supposed to inherit is broken? Further, why would you suggest I recreate functionality using custom implementation when I should be able to take advantage of existing functionality you provide, especially when I am allowed to derive? Your suggesting I recreate the entire set of filter options presented for one of your column types? You might be surprised to find out the issue could be a bigger problem than just dateColumn.
I logged a development issue because there is obviously a problem here in the software or a technical details I am missing in my implementation that needs to be addressed when deriving from a column.
*Also, at this time 12.1 is not an option for me.
Thank you for looking into this.