This project is read-only.

Filtering Date

Oct 10, 2013 at 1: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 5: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 6: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 4:00 AM
Yep, http://gridmvc.azurewebsites.net/?grid-filter=OrderCustomDate__6__1998-05-01&grid-filter=OrderCustomDate__5__1998-04-28

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 10: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.

Regards
Oct 22, 2013 at 12:01 PM
Edited Oct 22, 2013 at 12:34 PM
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")
                        .Format("{0:dd/MM/yyyy}")
                        .Filterable(true)
                        .SetWidth(70);
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 4:26 PM
I've create 2 new filter types at server side: GreaterThanOrEquals and LessThanOrEquals - https://gridmvc.codeplex.com/SourceControl/changeset/26714

You can update package - http://www.nuget.org/packages/Grid.Mvc/3.0.0

Now you can use client side to build query as you need - http://gridmvc.azurewebsites.net/?grid-filter=OrderCustomDate__7__1998-05-01&grid-filter=OrderCustomDate__6__1998-05-02 - 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 10:44 AM
Edited Oct 23, 2013 at 10: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.

ie

SELECT * FROM [TABLENAME]
WHERE DATE BETWEEN "fromDate" AND "toDate"