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

How to filter a formatted Gridview date column

2 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 16 May 2011, 01:37 PM

I have what I think should be an easy question.
I have a database field which stored the timestamp. (date and time).
I want to display the timestamp as 2 columns, upload date and upload time. (please see below)
To do this I simply bind my timestamp db field (AddedDate) to both GridView columns and then apply a date format to the first one and a time format to the second one.

The problem is that when I click on the filter for the "upload date", I get the same value in the filter multiple times. It looks like this is due to the fact that the filter is applied to the underlying field value which has a time component.

In other words, based on the data:

5/1/2011 08:30:25
5/1/2011 09:45:32
5/1/2011 10:44:33

My gridview correctly displays the previous data in 2 gridview columns. (Upload Date, Upload Time)
However, when I click on the filter for the Upload Date, I get the following:

5/1/2011
5/1/2011
5/1/2011

I do not want this. I only want 5/1/2011 displayed a single time.
Is there a way to have the Telerik Gridview filter on the displayed value and not the underlying "raw" value?
Or is there another way to handle this?

Thanks

Jim

james_williamson@nylim.com    


<telerik:RadGridView x:Name="HistoricalFilesGrid" ItemsSource="{Binding HistoricalFilesView}" Grid.Row="1" SelectionMode="Multiple" AutoGenerateColumns="False" SizeChanged="HistoricalFilesGrid_SizeChanged" IsReadOnly="True" Filtered="HistoricalFilesGrid_Filtered">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding AddedDate}" DataFormatString="{}{0:MM/dd/yyyy}" Header="Upload Date"></telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding AddedDate, StringFormat='hh:mm'}" Header="Upload Time" IsFilterable="False"></telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 May 2011, 09:39 AM
Hello James,

 The behavior that you would like to have can be achieved by specifying the .Date property when binding to AddedDate like:

<telerik:GridViewDataColumn DataMemberBinding="{Binding AddedDate.Date}" DataFormatString="{}{0:MM/dd/yyyy}" Header="Upload Date"></telerik:GridViewDataColumn>

Now you are binding to AddedDate and after that you apply formating for showing only the date. This way you see only some part of the binded value, but the associated value is the original full value. The filtering mechanism operates with the original binded value (the underlined "raw" value), not the shown formatted one. That is why it shows all the distinct values of AddedDate, not the distinct values of the Date of AddedDate.

Regards,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James
Top achievements
Rank 1
answered on 23 May 2011, 07:42 PM

Hi Didie,

That worked perfectly !!!

Thanks very much.

Jim
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
James
Top achievements
Rank 1
Share this question
or