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

changing filterDescriptor

8 Answers 354 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alan Mosley
Top achievements
Rank 1
Alan Mosley asked on 11 Jul 2014, 05:55 AM
I need to change a filterDescriptors member from FranchiseeName to Franchisee.Name.
Note that the field is "Name" from a related included table called Franchisee

so far I have
If request.Filters.Any() Then
              If request.Filters.Any(Function(y) CType(y, Kendo.Mvc.FilterDescriptor).Member.Equals("FranchiseeName")) Then
                  Dim filter As FilterDescriptor = request.Filters.Single(Function(g) CType(g, Kendo.Mvc.FilterDescriptor).Member.Equals("FranchiseeName"))
                  request.Filters.Add(New Kendo.Mvc.FilterDescriptor With {.Member = "Franchisee.Name", .Value = filter.Value.ToString})                      
                  request.Filters.Remove(filter)
              End If


but this does not work. It adds the descriptor and removes old descriptor as planed without error but query fails. 

in this post I see a simple field change can be achieved. but in my case this does not work.
http://www.telerik.com/forums/how-to-access-datasourcerequest-filters-in-controller-

Any ideas, Thanks

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 15 Jul 2014, 05:32 AM
Hi Alan,

Have you tried just setting the Member property instead of removing the filter descriptor? Also what does "jquery fails" mean? Providing more details would allow us to be more specific.

Regards,
Atanas Korchev
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
Alan Mosley
Top achievements
Rank 1
answered on 15 Jul 2014, 09:43 AM
Yes I have, but the problem lies because the FieldName is on a related table like RelatedTable.FieldName

Thanks
0
Atanas Korchev
Telerik team
answered on 16 Jul 2014, 07:25 AM
Hello Alan,

I am still not sure what the actual problem is. Please clarify what you are trying to implement and what the current behavior is. So far I understood that you want to change the member property of a filter descriptor (which is supposed to work) but you got a jQuery error (not clear what).

Regards,
Atanas Korchev
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
Alan Mosley
Top achievements
Rank 1
answered on 16 Jul 2014, 07:50 AM
Hi Atanas, I don't get a jQuery error, What I said was that the query fails.

My problem is that changing member is not working, because the database field I want to change to is on a related table See attached file.
Thanks

0
Atanas Korchev
Telerik team
answered on 16 Jul 2014, 08:10 AM
Hello Alan,

Does it work if you filter your data manually via the LINQ Where extension method? Does the query run as expected? I am asking you this because under the hood the ToDataSourceResult method uses similar code to do the filtering. 

Please paste here the error which the query fails with.

Regards,
Atanas Korchev
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
Alan Mosley
Top achievements
Rank 1
answered on 16 Jul 2014, 08:16 AM
I don't get an error, it just does not return any results, I solved the problem using the below code, but was hopping I would not have to write such code for each time I have this problem.

‚Äč
Dim filterDescriptors As List(Of FilterDescriptor) = New List(Of FilterDescriptor)
If request.Filters.Any() Then
    Dim filterValue As String = String.Empty
    For Each filterDescriptor As FilterDescriptor In request.Filters
 
        Select Case filterDescriptor.Member
            Case "FranchiseeName"
                filterDescriptors.Add(filterDescriptor)
                filterValue = filterDescriptor.ConvertedValue
                Select Case filterDescriptor.Operator
                    Case FilterOperator.Contains
                        data = data.Where(Function(w) w.Franchisee.Name.Contains(filterValue))
                    Case FilterOperator.DoesNotContain
                        data = data.Where(Function(w) Not w.Franchisee.Name.Contains(filterValue))
                    Case FilterOperator.EndsWith
                        data = data.Where(Function(w) w.Franchisee.Name.EndsWith(filterValue))
                    Case FilterOperator.IsEqualTo
                        data = data.Where(Function(w) w.Franchisee.Name.Equals(filterValue))
                    Case FilterOperator.IsNotEqualTo
                        data = data.Where(Function(w) Not w.Franchisee.Name.Equals(filterValue))
                    Case FilterOperator.StartsWith
                        data = data.Where(Function(w) w.Franchisee.Name.StartsWith(filterValue))
                End Select
        End Select
    Next
    For Each filterDescriptor As FilterDescriptor In filterDescriptors
        request.Filters.Remove(filterDescriptor)
    Next
End If
If request.Filters.Any() Then
    data = data.Where(ExpressionBuilder.Expression(Of EF.Student)(request.Filters))
End If
0
Atanas Korchev
Telerik team
answered on 18 Jul 2014, 07:11 AM
Hello,

I couldn't reproduce this problem in the attaches sample project. Try filtering on CategoryName.

Regards,
Atanas Korchev
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
Alan Mosley
Top achievements
Rank 1
answered on 18 Jul 2014, 12:40 PM
Thanks, I gave it another it and it worked, thanks
Tags
Grid
Asked by
Alan Mosley
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Alan Mosley
Top achievements
Rank 1
Share this question
or