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

Removing specific filters from Request.Filters

2 Answers 168 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Denny
Top achievements
Rank 1
Denny asked on 20 Sep 2018, 10:47 PM

We're attempting to do custom filtering on the server-side by passing additional data via the filters. However these custom filters do not correlate to any of the properties of the result set so we end up with an error:

Invalid property or field - 'GroupNameId' for type: InventorySearchResult

Unfortunately its not as simple as adding the GroupNameId to the result because GroupNameId is in a collection of Group Names, example:

MyEntity {
 Id = 1,
 Name = "name",
 GroupNames = <Collection of Group Names that I want to further filter against>
}

So what we do is query our data via IQueryable, extract the GroupNameGid filter from Request.Filters, then manually apply a filter for GroupNameGid to the expression, then we return the data via ToDataSourceResult(...). Unfortunately this results in the error mentioned above. I thought maybe I could remove the GroupNameGid filter from Request.Filters since I'm manually applying the filter and let ToDataSourceResult apply the rest of its magic. However this turned out to be rather complicated due to CompositeFilterDescriptor. So I'm curious to know if there is any way to easily remove a specific filter from request.Filters.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetina
Telerik team
answered on 24 Sep 2018, 12:52 PM
Hi Denny,

I think it would be best to pass the additional values as a standalone parameter and not as a part of the filter expression. You can use  the Data method that specifies a JavaScript function, which will return the additional parameters.
.Read(read => read.Action("Products_Read", "Grid").Data("additionalInfo"))

function additionalInfo() {
    return {
        name: "test",
        id: 2
    }
}

Then, in the controller method, list the additional values as arguments:
public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request, string name, int id) {...}

You can pass any number of values and access them as separate arguments of the controller action method. In this way, you will not need to modify the DataSourceRequest filters manually.

Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Denny
Top achievements
Rank 1
answered on 24 Sep 2018, 07:01 PM

Yes, the more I dig into this the more I agree, these should be handled separately.

Thanks!

Tags
General Discussions
Asked by
Denny
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Denny
Top achievements
Rank 1
Share this question
or