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

RadGrid: Case-Insensitive LINQ Filter using Web Service

3 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 12 Jan 2012, 03:29 PM
I have a grid, bound declaratively to a PageMethod web service, using LINQ filtering with System.Linq.Dynamic.
Some of my settings are as follows:

<GroupingSettings CaseSensitive="false" />
<ClientSettings>
<DataBinding SelectMethod="GetAllOffices" Location="UserDetails.aspx" EnableCaching="true" FilterParameterType="Linq" />
<Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true" />
</ClientSettings>
<MasterTableView>

I understand that <GroupingSettings> should be used for case-insensitive filtering, but that is not holding true when using client-side LINQ binding.  Fiddler shows the dynamic LINQ statement being returned to server, as JSON, to be:  "filterExpression":"OfficeName.Contains(\"name\") AND OfficeCode.Contains(\"c\")".

How do you get case-insensitivity when using a LINQ filter, bound declaratively, to a web service?

Thank you,
Kevin Kalitowski 

3 Answers, 1 is accepted

Sort by
0
The Oracle
Top achievements
Rank 1
answered on 29 Aug 2012, 12:29 AM
Can someone answer this question?  I have the same issue.
Thank you much!
0
Kevin
Top achievements
Rank 1
answered on 29 Aug 2012, 01:12 PM
Hey Oracle, this is the solution I have for the problem.

These are my relevant ClientSettings in the RadGrid:
<ClientSettings>
    <DataBinding SelectMethod="GetAllOffices" Location="UserDetails.aspx" FilterParameterType="Linq" />
    <ClientEvents OnDataBinding="OfficeGridDataBinding" />
</ClientSettings>

This is the OnDataBinding function.  I also included two lines for sending an extra parameter to the web method as I thought you might find that as useful as I did.
function OfficeGridDataBinding(sender, e) {
    //Adds an additional parameter to the JSON web service call
    var methodArguments = e.get_methodArguments();
    methodArguments.previouslySelectedOfficeIds = $('#previouslySelectedOfficesHiddenField').val();
    MakeSearchCaseInsensitive(sender, e);
}

And here is the magic.  In summary, it uses JavaScript regular expressions to add a ".ToLower()" string in the appropriate places which is interpreted by dynamic LINQ:
function MakeSearchCaseInsensitive(sender, args) {
    var master = sender.get_masterTableView();
    if (master.get_filterExpressions().get_count()) {
        //get the filter expression string that will be sent to your web service
        var filterExpression = args.get_methodArguments().filterExpression;
 
        for (var i = 0; i < master.get_filterExpressions().get_count(); i++) {
            //for each filter expression item in the collection, modify the above
            //filter expression if the filter data type is System.String
            var expr = master.get_filterExpressions().getItem(i);
            if (expr.get_dataTypeName() === "System.String") {
                filterExpression = filterExpression.replace(new RegExp(expr.get_fieldName(), "gim"), expr.get_fieldName() + ".ToLower()");
                filterExpression = filterExpression.replace(new RegExp('"' + expr.get_fieldValue() + '"', "gim"), '"' + expr.get_fieldValue() + '".ToLower()');
 
                //set the modified filter expression back in the method arguments
                args.get_methodArguments().filterExpression = filterExpression;
            }
        }
    }
}

Good luck!
0
The Oracle
Top achievements
Rank 1
answered on 30 Aug 2012, 02:03 PM
Dude, thanks for this.  It seems like 95% of dev time is spent trying to get controls to work the way they are purported to or to work in "unanticipated" scenarios. LOL.  telerik still has a great toolset.
Graeme
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
The Oracle
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Share this question
or