I've been struggling to find a better way to filter an ObservableArray to a subset of values. At first glance it seems like this should be easy. Simply add a function to the view model to create an array with only those items I want and then set the binding source to that function.
Here's an example:
<ul class="items" data-template="row-template" data-bind="source: itemsFiltered"></ul>
itemsFiltered : function () {
var iFlt = [];
var iCurr = this.get("Items");
for (var i = 0; i < iCurr.length; i++) {
if (iCurr[i].get("State") != "CA") { //Ex: filter out all items in CA
iFlt.push(iCurr[i]);
}
}
return iFlt;
}
This sort of works, but I'm getting some strange Focus and Blur behaviors in IE when binding to the Filter function. These behaviors go away if I bind directly to the array.
I can't help but think that IE doesn't like the fact that I'm replacing the entire array each time the view model changes. I know KnockOut has a utility function to handle filtering like this (ko.utils.arrayFilter), and such a function is more ideal than returning a new array.
Does Kendo MVVM contain an equivalent to ko.utils.arrayFilter? If so, what is it? If not, I'd like to recommend adding such a function. Ideally the binding features of kendo should call always call a filter function (default implementation would return a value of true) when evaluating the binding of each item.
Is there another way to accomplish filtering in kendo MVVM? I know I could theoretically add an binding for invisible and point to a function that evaluates whether or not to display the item, but this is only a partial solution as the item itself would still be in the DOM.
Here's an example:
<ul class="items" data-template="row-template" data-bind="source: itemsFiltered"></ul>
itemsFiltered : function () {
var iFlt = [];
var iCurr = this.get("Items");
for (var i = 0; i < iCurr.length; i++) {
if (iCurr[i].get("State") != "CA") { //Ex: filter out all items in CA
iFlt.push(iCurr[i]);
}
}
return iFlt;
}
This sort of works, but I'm getting some strange Focus and Blur behaviors in IE when binding to the Filter function. These behaviors go away if I bind directly to the array.
I can't help but think that IE doesn't like the fact that I'm replacing the entire array each time the view model changes. I know KnockOut has a utility function to handle filtering like this (ko.utils.arrayFilter), and such a function is more ideal than returning a new array.
Does Kendo MVVM contain an equivalent to ko.utils.arrayFilter? If so, what is it? If not, I'd like to recommend adding such a function. Ideally the binding features of kendo should call always call a filter function (default implementation would return a value of true) when evaluating the binding of each item.
Is there another way to accomplish filtering in kendo MVVM? I know I could theoretically add an binding for invisible and point to a function that evaluates whether or not to display the item, but this is only a partial solution as the item itself would still be in the DOM.