Filtering Date

Oct 10, 2013 at 12:56 PM
I have in a column datetime value. I need a filter for that column by date only.
The problem is that this grid takes also time. So I changed the source for DateTimeFilterType.cs with this code:
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
            if (filterType == GridFilterType.Equals)
                var startDate = Expression.Constant(Convert.ToDateTime(value));
                var endDate = Expression.Constant(Convert.ToDateTime(value).AddDays(1));

                var left = Expression.GreaterThanOrEqual(leftExpr, startDate);
                var right = Expression.LessThan(leftExpr, endDate);

                return Expression.And(left, right);
            return base.GetFilterExpression(leftExpr, value, filterType);
Is there a posibility to include this as date filter to have to filters.

The problem is also that you made those classes internel. So I need to compile it and cannot use nuget.
Oct 11, 2013 at 4:24 AM
That's a problem to filter date time field without time portion.
But modification of DateTimeFilterType it's a not good idea, I think. Because in other case you need to filter date with Time portion.

Since 3.0 grid support multiple filters per one column, and I think that we can create custom filter widget that will pass 2 filter values (greaterThan and lessThan) to get this behavior.

I create an new Issue on this problem and try to resolve it in the next release
Oct 11, 2013 at 5:52 AM
I guess at this release there is nothing I can do about it then I already did.

I don't know if I understand but filter widget is only on client side or. Is there any demo about multiple filter per one column?

Thank you
Oct 16, 2013 at 3:00 AM

There is 2 filters: less than 1998-05-01 and greater than 1998-04-28
But I guess that we need to create a new filter types: greater than or equals and less than or equals to create this behaviour
Oct 22, 2013 at 9:41 AM
Hi Bukharin,

With regards to your last post on Oct16 @ 16:00,

Could you provide further information on how to implement Filtering by date, which has a 'Date From' and 'Date To: parameter ?

I know how to create a new filter type, but how to create one filter type for : greater than or equals and less than or equals to create this behaviour.

Oct 22, 2013 at 11:01 AM
Edited Oct 22, 2013 at 11:34 AM
I am working on getting a datetime filter working.

I have used nuget to get the grid.mvc datepicker

I am referencing these at the top of my view.
@using GridMvc.Filtering
@using GridMvc.Html

and in my "_layout" i link to all the js files (bootstrap-datepicker.js)

in my code I have

columns.Add(c => c.StartDate)
                        .Titled("First Insert Date")
The format is working (it is not showing the time so thats good). But the filter being selected is the standard one. How do i force it to use the datetime picker? Do i need to reference something else?
Oct 22, 2013 at 3:26 PM
I've create 2 new filter types at server side: GreaterThanOrEquals and LessThanOrEquals -

You can update package -

Now you can use client side to build query as you need - - greater than or equals 1998-05-01 and less than 1998-05-02

I am not fix client side filter widgets to use new api.
Oct 23, 2013 at 9:44 AM
Edited Oct 23, 2013 at 9:44 AM
Hi Bukharin,

Thanks for this new feature it looks great and I will be making good use of this feature. :)

Also what would be nice is to filter by date Between "FROM DATE" and "TO DATE", on the same column.


WHERE DATE BETWEEN "fromDate" AND "toDate"