data KendoFilter returns undefined.

0 Answers 20 Views
Filter
Patrick
Top achievements
Rank 1
Patrick asked on 25 Mar 2025, 05:49 PM

Attempting to create persistence on filter.

I have the following filter:

                    @(Html.Kendo().Filter<...>()
                        .Name("fltMatrix")
                        .Events(e => e.Change("fltMatrix_Change"))
                        .DataSource("dataSource1")
                        .ExpressionPreview()
                        .Fields(f =>
                        {
...
                        }))
                    @Html.HiddenFor(model => model.FILTER)


I have the following JS code:

    function fltMatrix_Change(e) {
        e.sender.applyFilter();
        $("#FILTER").val(JSON.stringify(e.expression));
    }

    function getInitialExpression() {
        if ($("#FILTER").val()) {
            return JSON.parse($("#FILTER").val());
        }
    }

document.ready looks like this:


    $(document).ready(function () {
        if (getInitialExpression()) {
            var filter = $("#fltMatrix").data("kendoFilter");
            console.log(filter);
            var options = filter.getOptions();
            options.expression = getInitialExpression();
            filter.setOptions(options);
            filter.applyFilter();
        }
    });

console shows undefined and I get an error on the highlighted line:

jQuery.Deferred exception: Cannot read properties of undefined (reading 'getOptions') TypeError: Cannot read properties of undefined (reading 'getOptions')  

Everything else seems to work OK.  The filter is loading and updating the data source on change. The filter expression makes the round trip to the server and back.  It is just the .data("kendoFilter") that comes back with nothing.

Patrick
Top achievements
Rank 1
commented on 26 Mar 2025, 11:32 AM

I replaced the MVC instantiation with a jquery equivalent (based off the sync creation that the MVC wrapper actually created) and it seems to work.

Not sure why that occurs.

Eyup
Telerik team
commented on 27 Mar 2025, 03:28 PM

Hi Patrick,

I am glad it is working now, but I also wrote you in the formal support ticket.
I suggest that we continue our technical conversation there.

No answers yet. Maybe you can help?

Tags
Filter
Asked by
Patrick
Top achievements
Rank 1
Share this question
or