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

Filter with dynamic datasource

1 Answer 518 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Syleps
Top achievements
Rank 1
Veteran
Syleps asked on 22 Dec 2020, 02:51 PM

Hi,

I’m trying to use the filter component with dynamic datasource. (Asp.net MVC)
I'm writing something like this:
    @(Html.Kendo().Filter<dynamic>()
        .Fields(f =>
        {
            foreach (var field in Model.Fields)
            {
                f.Add().Label(field.Label).EditorTemplateHandler(“func”+field.type);            
            }
        }).FilterExpression(f =>
        {
            f.AddRange(Model.Filters);
        }))




For filters, I had to create my own conversion function (string json -> IFilterDescriptor) because I couldn't get the one used for the grids to work (= FilterDescriptorFactory.Create)

And now, I am blocked by the dynamic change of operators. These change depending on the type of field. However, I do not pass a field (because dynamic), and I do not have a "SetType" function as for "kendo-ui" (https://docs.telerik.com/kendo-ui/api/javascript/ui/filter/configuration/fields.type)

How can I do ?

Regards
P.S. I'm with v2020.3.915

1 Answer, 1 is accepted

Sort by
0
Preslav
Telerik team
answered on 24 Dec 2020, 09:04 AM

Hi Syleps,

Indeed, usually, the Filter is setting the operators based on the Fields type in the model of the DataSource. Thus, our MVC wrapper component was not designed to work with a dynamic model.

Having said that, as you already noticed, the jQuery Kendo UI Filter can set the type of the field inside the Filter fields configuration. If possible, I would recommend switching to the Kendo UI for jQuery Filter for this specific scenario.

 

Regards,
Preslav
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Filter
Asked by
Syleps
Top achievements
Rank 1
Veteran
Answers by
Preslav
Telerik team
Share this question
or