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.
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.
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.