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

Filtering by date

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Taylor
Top achievements
Rank 1
Paul Taylor asked on 05 Apr 2011, 06:35 PM
I have a grid with filtering enabled, bound to a DataTable object so that it supports automatic sorting.

There is a date field in the table, and as the RadGrid needs the date converting to mm/dd/yyyy format before it will filter correctly, I have intercepted the Filter command, cancelled it, and have rebound the list with the FilterExpression correctly set. See code below.

        protected void rgResults_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.Item is GridFilteringItem)
                {
                    Pair filterPair = (Pair)e.CommandArgument;
                    if (e.CommandName == RadGrid.FilterCommandName && filterPair.Second.ToString() == "Date")
                    {
                        e.Canceled = true;
                        GridFilteringItem item = (GridFilteringItem)e.Item;
                        GridBoundColumn col = (GridBoundColumn)item.OwnerTableView.GetColumnSafe(filterPair.Second.ToString());
                        DateTime date = DateTime.Parse(col.CurrentFilterValue);
                        item.OwnerTableView.FilterExpression = string.Format("([{0}] {1} #{2}#)", filterPair.Second.ToString(),       
                                                                      GetOperator(filterPair.First.ToString()), date.ToString("d", new CultureInfo("en-US")));
                        item.OwnerTableView.Rebind();
                    }
                }
...

To create the filter expression in T-SQL syntax, I need to get the T-SQL equivalent of the RadGrid filter operator. Is there a function I can use to do this? The grid obviously has to do the same to construct the filter expression, so I guess the functionality is in there somewher. Is it available through the API?

Thanks in advance,

1 Answer, 1 is accepted

Sort by
0
Paul Taylor
Top achievements
Rank 1
answered on 05 Apr 2011, 09:14 PM
Found the answer: the documentation that I was following is out of date. No special action is needed to filter by date. Just removed the code and it worked!
Tags
Grid
Asked by
Paul Taylor
Top achievements
Rank 1
Answers by
Paul Taylor
Top achievements
Rank 1
Share this question
or