Remote Sorting with IListDataSource? RRS feed

  • Question

  • I like the abstraction created by the data store (i.e., IListDataSource) and data adapter (i.e., IListDataAdapter).  Does anyone have any guidance or best practices on how to implement features such as remote filtering and sorting? 

    I imagine this would look something like this:

    1. Add methods to IListdataSource implementation.  E.g.,
      • AddFilter(property, value)
      • SortBy(property, direction)
    2. Clear local cache whenever values change.
    3. Serialize sorting and filtering as part of query.
    4. Parse query as appropriate for remote data source in IListDataAdapter.

    I haven't actually implemented this yet, but before I do wanted to check with the community on their experiences, as I'm sure other folks have gone down this path.  While the IListDataAdapter provides an elegant abstraction for paging, it seems to assume sorting and filtering will generally be done client side against a cached data store.

    Tuesday, July 3, 2012 1:12 AM



    Hi Jeremy, 

    The data adapter is pretty much stateless, so when the user changed the sort or filter you'd want to clear the cache in the VirtualizedDataSource (VDS). It will then go ask the data adapter for the new data.


    If the dataset is small enough that the dataadapter has its own cache, it can do a sort/filter and represent the data to the VDS, which will then cause lists & other bindings to get the change notifications.


    If the dataset is large, you probably need to do the sort / filter on the server, discard the local cache and re-request the data required for the view. The dataadapter will need to get the query parameters and feed them into the request URL etc. The way we had designed this to happen is that the listview should have its datasource property (and group datasource if applicable) set to a new instance of the datasource. That way the old cache etc is guaranteed to be cleared out. The control will also do an exit & entrance animation for the new query.


    For an example of the latter, see the Listview working with datasources sample. If you change "cats" to a different search term, then it just instances a new datasource which is then set on the list.


    Jeff Sanders (MSFT)

    • Marked as answer by Dino He Tuesday, July 10, 2012 1:20 AM
    Monday, July 9, 2012 11:38 AM