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

Unable to cast object of type 'Kendo.Mvc.CompositeFilterDescriptor' to type 'Kendo.Mvc.FilterDescriptor'

1 Answer 610 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 10 Dec 2014, 09:32 AM
I am trying to alter the meber name of a filterdescriptor but get error Unable to cast object of type 'Kendo.Mvc.CompositeFilterDescriptor' to type 'Kendo.Mvc.FilterDescriptor'  here

If request.Filters.Any(Function(y) CType(y, Kendo.Mvc.FilterDescriptor).Member.Equals("FranchiseeName")) Then
 
                     Dim filter As FilterDescriptor = CType(request.Filters.Single(Function(g) CType(g, Kendo.Mvc.FilterDescriptor).Member.Equals("FranchiseeName")), FilterDescriptor)
                     filter.Member = "Franchisee.Name"
 
 
                 End If

I don't know what the difference is or why I get this, I have done simular before without this problem.
Thanks

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 12 Dec 2014, 08:49 AM
Hi Alan,

There are two concreate implementation of IFilterDescriptor - the CompositeFilterDescriptor and the FilterDescriptor. CompositeFilterDescriptor class is required as the filters can be complex - multiple filters with And or Or logic. Therefore, usually the FilterDescriptors are nested within an instance of CompositeFilterDescriptor. Therefore in order to iterate over the filters you will need to conditionally navigate to through the CompositeFilterDescriptor's FilterDescriptors property. Similar to the following:

private void ChangeMemberName(IEnumerable<IFilterDescriptor> filters, string memberToSearchFor, string newMemberName)
{
    foreach (var filter in filters)
    {
        if (filter is CompositeFilterDescriptor)
        {
            ChangeMemberName(((CompositeFilterDescriptor)filter).FilterDescriptors, memberToSearchFor, newMemberName);
        }
        else if (((FilterDescriptor)filter).Member == memberToSearchFor)
        {
            ((FilterDescriptor)filter).Member = newMemberName;
        }
    }
}
 
public ActionResult Customers_Read([DataSourceRequest]DataSourceRequest request)
{
    if (request.Filters.Any())
    {
        ChangeMemberName(request.Filters, "FranchiseeName", "Franchisee.Name");
    }
 
   /*..*/
}


Regards,
Rosen
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.

 
Tags
Grid
Asked by
Alan Mosley
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or