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

[Solved] "EqualTo" filter not working properly for filtering date ?

4 Answers 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bibhudutta
Top achievements
Rank 1
Bibhudutta asked on 30 Jan 2012, 09:13 AM
Out of all the columns present in my grid, I have four columns which hold date values. I want to filter the grid according to the date, so I have wriiten the following code

                    <telerik:GridBoundColumn UniqueName="OrderDate" DataField="OrderDate" HeaderText="Ordered on"
                        CurrentFilterFunction="EqualTo" DataType="System.DateTime" ShowFilterIcon="False"
                        AutoPostBackOnFilter="True" DataFormatString="{0:MM/dd/yy}">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" Width="65px" />
                    </telerik:GridBoundColumn>

                    <telerik:GridBoundColumn UniqueName="ScheduledShipDate" DataField="ScheduledShipDate"
                        HeaderText="Ship By" CurrentFilterFunction="EqualTo" DataType="System.DateTime"
                        ShowFilterIcon="False" AutoPostBackOnFilter="True" DataFormatString="{0:MM/dd/yy}">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" Width="65px" />
                    </telerik:GridBoundColumn>

                    <telerik:GridBoundColumn UniqueName="Deliveron" DataField="ScheduledDeliveryDate"
                        HeaderText="Deliver on" CurrentFilterFunction="EqualTo" DataType="System.DateTime"
                        ShowFilterIcon="False" AutoPostBackOnFilter="True" DataFormatString="{0:MM/dd/yy}">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" Width="65px" />
                    </telerik:GridBoundColumn>

                    <telerik:GridBoundColumn UniqueName="ActualShip" DataField="ActualShipDate" DataFormatString="{0:MM/dd/yy}"
                        HeaderText="Actual Ship" CurrentFilterFunction="EqualTo" DataType="System.DateTime"
                        ShowFilterIcon="False" AutoPostBackOnFilter="True">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" Width="65px" />
                    </telerik:GridBoundColumn>

Out of the four columns the last three are working perfectly but the first one is not filtering, but it has the same set of attributes written as that of the other columns.

Please help me out.

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jan 2012, 09:19 AM
Hello  Bibhudutta,

For that you have to manually managed by your way using below link
http://www.telerik.com/help/aspnet/grid/grdfilteringfordatetimecolumnwithdataformatstring.html

OR

Assign the only DATE to the column. (Remove time part from your field's value)

Thanks,
Jayesh Goyani
0
Bibhudutta
Top achievements
Rank 1
answered on 30 Jan 2012, 09:41 AM
Hi Jayesh,

But I am using date format of "mm/dd/yyyy", so how come the link you have shared is related to my problem. The link explains for Date formats other than "mm/dd/yyyy".
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jan 2012, 10:06 AM
Hello,

Please try with above link.
Its also worked for you.

Note : there is a little change in filter pattern else whole code are correct for your requirement.

Thanks,
Jayesh Goyani
0
B
Top achievements
Rank 1
answered on 22 Aug 2013, 11:27 AM
Hello,

I know its this thread is quiet old, and may be my reply would not useful to original poster "Bibhudutta". Though, I am sharing my experience, as I came across same problem recently. The way Jayesh has suggested should certainly work.

If not here are some more ideas:
I tend to believe you would have Time part in your database value i.e. 2013-08-22 12:07:08.340
So when you choose EqualTo, it doesn't work obviously as comparing your plain date part filter (even if it is dd/mm/yyyy) with date value with   time part returns false.


  • On the other hand you can try to push this on database side by truncating time part manually in your T-SQL using something like
    SELECT
    cast(floor(cast(OrderDate as float)) as datetime)

  • Or setting database server setting using
    SET
    DATEFORMAT dmy
    Ref. Link

    Caution:
    This is not recommended as it changes format for database server itself, which may cause problems with any other applications using the same database server.

I hope this helps.

Thanks,
Bhavin Gosai



Tags
Grid
Asked by
Bibhudutta
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Bibhudutta
Top achievements
Rank 1
B
Top achievements
Rank 1
Share this question
or