wloescher
wloescher

Reputation: 4603

How to sort and filter a WinJS custom data source which implements IListDataAdapter?

I've created a custom data source for a ListView which implements the IListDataAdapter. The data comes from a couple different web services, and requires multiple asynchronous calls to get fully populated. The data populates correctly, and the ListView exhibits the nice "infinite scroll" functionality, loading new pages of data as needed.

I'm now trying to filter the data on a couple different properties. I have a checkbox and a drop down list, both of which have events which fire correctly. These events should call the updateLayout method...but for some reason that method ends up being undefined.

    checkBoxClick: function (eventObject) {
        this.updateLayout(document, Windows.UI.ViewManagement.ApplicationView.value);
    },

    dropDownListValueChange: function (eventObject) {
        this.updateLayout(document, Windows.UI.ViewManagement.ApplicationView.value);
    },

I'm hoping that somebody out there has a project that uses a custom data source and supports both sorting AND filtering, and would be willing to share that code with the class.

Upvotes: 1

Views: 1507

Answers (2)

Scott Isaacs
Scott Isaacs

Reputation: 1168

Most likely the this variable is not scoped correctly in your event handlers.

Upvotes: 0

louis.luo
louis.luo

Reputation: 2971

You could use the following API:

WinJS.Binding.List.createSorted(sortingFunction) and WinJS.Binding.List.createFiltered(filterFunction)

You should bind your dataSource to the view first with the "sorted" or "filtered" WinJS.Binding.List. Then any newly added value to the same dataSource would get updated by itself.

P.S. I also noticed that you are using updateLayout. I don't know whether it is relevant to your problem, but ever since Windows 8 release, it started to use a function called initializeLayout to update the view.

Upvotes: 2

Related Questions