I've been struggling to get something similar working for the last few days. Best I can tell, using a function operator makes Kendo expect a function value as well. Problem is, that function gets executed on the window context so I can't use it to access any of my locally defined variables. You can get around that by scrapping the value declaration entirely
and just grabbing your val variable in the operator function.
I can't find much of anything in the API docs describing the function variants of the operator/value/field declarations on datasource filters.