Oliver Weichhold
Oliver Weichhold

Reputation: 10296

Force re-evaluation of live-filtered IListDataSource

I'm using a live-filtered projection over a WinJS.Binding.List created using createFiltered().

The filter predicate operates on a string variable that is set by an event handler listening to Windows.ApplicationModel.Search.SearchPane.getForCurrentView().onquerysubmitted.

How do I trigger a re-evaluation of the filtered projection when the search string changes?

Upvotes: 0

Views: 316

Answers (1)

Adam Freeman
Adam Freeman

Reputation: 1184

You need to change the variable that your predicate filter is using to inspect items and then call notifyReload() on the source list. Here is a little code fragment to demonstrate:

    var mainList = new WinJS.Binding.List(["one", "two", "three"]);

    var filterString = "t";

    function filter(item) {
        var result = item.indexOf(filterString) > -1;
        console.log("Filter: " + item + " " + result);
        return result;
    };

    var filteredList = mainList.createFiltered(filter);

    filterString = "e";
    mainList.notifyReload();

When notifyReload is called, the predicate will be reapplied to regenerate the contents of the filtered list. In this fragment, the call to console.log will let you see how the filter is being reapplied.

Upvotes: 5

Related Questions