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

[Solved] Filter RadGridView column based on just DATE part of Datetime and disregard the time factor

9 Answers 323 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.
Adi
Top achievements
Rank 1
Adi asked on 20 Sep 2010, 05:01 PM
Hi All,

When I try to apply a filter on a column which is bound to a Datetime type. The filtering considers date as well as time and in the filtering control I get separate entries for a single date because times are different. Now, I want to customize the filter so that same date acts as one filter criteria irrespective of the time. Can anybody tell me how can I go about achieving this?

Thanks,
Adi

9 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 20 Sep 2010, 05:04 PM
Hi Adi,

Try binding your column to the Date portion of your DateTime property:

DataMemberBinding="{Binding MyDateTimeProperty.Date}" ...

Hope this helps.

Greetings,
Veselin Vasilev
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
Adi
Top achievements
Rank 1
answered on 20 Sep 2010, 05:18 PM
Hi Veselin,

Thanks for the quick response!

I tried doing what you said. However if I do that, I don't seem to be getting a filter on that column.
0
Adi
Top achievements
Rank 1
answered on 21 Sep 2010, 03:04 PM
Can someone urgently let me know a solution to this problem, as it is critical to my project. I again restate my problem, I just to bind and filter based on Date part of a Datetime. I have tried implementing custom filter and also tried the above suggested solution but in vain. 
I would really appreciate if someone can suggest how do I go about solving this problem.

Thanks,
Adi
0
Adi
Top achievements
Rank 1
answered on 21 Sep 2010, 09:03 PM
Hi Veselin,

I tried to do a workaround by creating a converter that returns just the date part. In fact, I went ahead and changed the converter so that I forcibly set the time part of the date time to 12:00:00AM. But still the filter shows different entries for the same date (now having same time as well). I have attached a screen shot so that you can take a look. Wonder what is going wrong!

 
 
0
Veselin Vasilev
Telerik team
answered on 22 Sep 2010, 02:33 PM
Hi Adi,

Actually binding to the Date portion would not work, sorry for misleading you.
You should use the DataFormatString to achieve this easier.

If the Date and the Time part is equal the Filtering control should show only one value in its distinct values list.

Please check the attached project.

All the best,
Veselin Vasilev
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
Adi
Top achievements
Rank 1
answered on 22 Sep 2010, 02:48 PM
The problem is that the time part is different for different records on a same date, and I want to show a single value for a date (in the filtering control) irrespective of time. I am already using DataFormatString to display just the date part. Is there any way I can achieve the above in the filtering control.

Thanks,
Adi
0
Veselin Vasilev
Telerik team
answered on 22 Sep 2010, 04:11 PM
Hi Adi,

The easiest way is to define another property in your model which returns the Date portion of your real DateTime object and bind the column to it. Find attached the modified sample.

Best wishes,
Veselin Vasilev
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
Otávio
Top achievements
Rank 1
answered on 01 Oct 2010, 08:31 PM
I did something like this ...

If you must that TIME appears in the column, you can do this programaticaly in the RowLoaded event, and the values that you will use on filter (DATE part of Datetime) you should put in DataMemberBinding, you should use the DataFormatString, if you not, the Dates on filter will appears with "AM 12:00:00" (time part).

Here is an example:

My class:
public DateTime DataCriacao { getset; }
public DateTime DataCriacaoApenasData
{
      get { return DataCriacao.Date; }
      set { }
} My column in XAML file:
<telerik:GridViewDataColumn DataMemberBinding="{Binding DataCriacaoApenasData}"
                                                        Width="138" UniqueName="gvcDataCriacao" 
                                                        Header="Criado em"
                                                        DataFormatString="{} {0: dd, MMM-yyyy}" 
                                                        HeaderCellStyle="{StaticResource estilo}" />

My code:
e.Row.Cells.Single(c => c.Column.UniqueName == "gvcDataCriacao").Content = 
((wcf.myclass)e.Row.Item).DataAlteracao.ToString("dd, MMM,yyyy - H:mm");


I hope you understand, I'm a non native english speaker.
0
Adi
Top achievements
Rank 1
answered on 01 Oct 2010, 11:00 PM
Hi Otavio,

Really appreciate your response, however I was able to finish it off using the technique suggested by Vaselin! I apologize for not getting back and acknowledging it.

Regards,
Adi
Tags
GridView
Asked by
Adi
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Adi
Top achievements
Rank 1
Otávio
Top achievements
Rank 1
Share this question
or