This is a migrated thread and some comments may be shown as answers.

[Solved] Customising the Filter for datetimes

1 Answer 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Damon Luck
Top achievements
Rank 1
Damon Luck asked on 17 Dec 2010, 04:49 PM
I have a filter on a column displaying datetimes, I wish to be able to change the way it displays datetimes on the fly.

In my grid the user can switch the way the date is displayed in a cell (custom cell) during runtime.

How can I customise the dates shown in the filter? For instance just showing the time component or date component? I tried converting the DateTime to the appropriate string using a converter, however then the filter assumes it is a String and does string comparisons on the data rather than datetimes, and also if a user changes the datetime format the value hasn't changed so it doesn't get pushed through the converter.

Thanks for any help!

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 20 Dec 2010, 10:31 AM
Hello Damon Luck,

You can do two things:

1. Apply a DataFormatString to the DataMemberBinding of the respective column, for example:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                            Header="Est."
                            DataFormatString="{}{0:yyyy}"/>

You can use any of the standard .NET formats strings for dates.

In this way, the filtering UI will show the formatted values in the distinct values list, but underneath it the actual value will still be a DateTime value

2. If you want to change the settings of the two RadDateTimePicker editors in the lower part of the control, you can attach to the FieldFilterEditorCreated event of RadGridView. In the event handler check which is the column and if it is the one of interest cast the editor to RadDateTimePicker. You can then adjust anything on it -- for example you can make it show both date and time by adjusting its input mode.

I hope this helps. Let me know if there are problems.

Greetings,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Damon Luck
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or