changing filterDescriptor

9 posts, 0 answers
  1. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 11 Jul 2014 Link to this post

    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
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 15 Jul 2014 Link to this post

    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.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 15 Jul 2014 in reply to Atanas Korchev Link to this post

    Yes I have, but the problem lies because the FieldName is on a related table like RelatedTable.FieldName

    Thanks
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 16 Jul 2014 Link to this post

    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.

     
  6. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 16 Jul 2014 in reply to Atanas Korchev Link to this post

    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

  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 16 Jul 2014 Link to this post

    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.

     
  8. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 16 Jul 2014 in reply to Atanas Korchev Link to this post

    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
  9. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 18 Jul 2014 Link to this post

    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.

     
  10. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 18 Jul 2014 in reply to Atanas Korchev Link to this post

    Thanks, I gave it another it and it worked, thanks
Back to Top
UI for ASP.NET MVC is VS 2017 Ready