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

How Override Filter Pattern from RadGrid?

4 Answers 259 Views
Grid
This is a migrated thread and some comments may be shown as answers.
小章
Top achievements
Rank 1
小章 asked on 06 Feb 2015, 07:36 AM
I get below form RadGrid.MasterVradGrid.MasterTableView.FilterExpression
filterExpression="(RequiredDate = DateTime.Parse("1/27/2015 12:00:00 AM"))"
if (!string.IsNullOrWhiteSpace(filterExpression))
{
      query = query.Where(filterExpression);
}

Happen Exception.
======================================================================================================
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method, and this method cannot be translated into a store expression.
======================================================================================================

Because I use EF6 it no support 'System.DateTime.Parse' method

I want change filter expression ,I hope result below example.
query = query.Where("(RequiredDate >= DateTime(2015,1,29))");

How Override Filter Pattern from RadGrid?

4 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 10 Feb 2015, 03:50 PM
Hello,

It is not possible to change the default ways (patterns) that RadGrid is using when creating the filter expressions, but I could suggest that you take a look at the following article and see how the expressions are created, based on the data source:
You could also take a look at the following forum threads, where the same issue is discussed:
In the first forum thread you will find a custom method for changing the filter expression.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
 
0
Accepted
kuntal
Top achievements
Rank 1
answered on 11 Mar 2015, 09:27 AM
string FinalQuery = "";
            if (filter.Contains("DateTime.Parse("))
            {
                var filters = filter.Split(new string[] { "DateTime.Parse(" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < filters.Count(); i++)
                {
                    if (i != 0)
                    {
                        var oldDate = filters[i].Substring(1, 22);
                        var newDate = DateTime.Parse(oldDate);
                        filters[i] = filters[i].Replace('\"' + oldDate + "\")", "DateTime(" + newDate.Year + ',' + newDate.Month + ',' + newDate.Day + ',' + newDate.Hour + ',' + newDate.Minute + ',' + newDate.Second + ")");
                    }
                    FinalQuery = FinalQuery + filters[i];
                }
            }
            else
                FinalQuery = filter;
0
小章
Top achievements
Rank 1
answered on 13 Apr 2015, 05:36 AM

My solution

http://www.dotblogs.com.tw/yc421206/archive/2015/02/09/149434.aspx

 

0
小章
Top achievements
Rank 1
answered on 13 Apr 2015, 05:38 AM
private static string GetNewDateExpression(string predicate)
{
    var split = predicate.Split(chars, StringSplitOptions.RemoveEmptyEntries);
    if (split.Count() > 1)
    {
        StringBuilder sb = new StringBuilder();
        foreach (var element in split)
        {
            DateTime result;
            if (DateTime.TryParse(element, out result))
            {
                var format = string.Format("DateTime({0},{1},{2},{3},{4},{5})",
                    result.Year,
                    result.Month,
                    result.Day,
                    result.Hour,
                    result.Minute,
                    result.Millisecond);
                sb.Append(format);
            }
            else
            {
                sb.Append(element);
            }
        }

        predicate = sb.ToString();
    }
    return predicate;
}
Tags
Grid
Asked by
小章
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
kuntal
Top achievements
Rank 1
小章
Top achievements
Rank 1
Share this question
or