7

I have a server-side API which provides paged data in JSON format based on various query parameters. I would like to provide a UI that allows the user to paged through the results of a query.

I am aware of the various component parts that permit this sort of interface, IPagedCollectionView and ICollectionView at the model / view model lever and DataPager within the UI. However, all the examples I have seen implement paging on top of data which has already been loaded into the model or view model.

I was hoping to find an IPagedCollectionView implementation somewhere, where you simple plug in your 'fetcher' method that fetches a given page of data from the server, plus provides a bit of metadata (total pages etc ...)

I could write this myself based on the IPagedCollectionView and ICollectionView interfaces, but I would be surprised if there is not a standard solution to this problem.

Any pointers to more suitable parts of the framework or libraries that extend the framework would be appreciated!

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
ColinE
  • 68,894
  • 15
  • 164
  • 232

2 Answers2

3

We had the same question and we settled with the new DomainCollectionView which is part of the WCF RIA Services SP1. Which of couse means you have to use RIA Services, don't know if that's an option.

The DomainCollectionView (which already implements the desired IPagedCollectionView interface) comes in combination with a DomainCollectionViewLoader which can be used to fetch the data for the current page.

For me this blog post by Kyle McCellan was very helpful:

http://blogs.msdn.com/b/kylemc/archive/2010/12/02/introducing-an-mvvm-friendly-domaindatasource-the-domaincollectionview.aspx

[Update] You may also find this Blog post helpful:

http://weblogs.asp.net/manishdalal/archive/2009/10/01/silverlight-3-custom-sorting-with-paging-support.aspx

It is a custom implementation of the IPagedCollectionView interface. We use it in one place where we aggregate Data from different datasources and a DomainCollectionView was not applicable.

stefan.s
  • 3,489
  • 2
  • 30
  • 44
  • Thanks - I have no objections to using RIA Services if it gives me some benefit. I'll take a look at that blog post. Thank you! – ColinE Aug 09 '11 at 12:21
  • Thanks for the update, looks like that blogpost has exactly what I need! – ColinE Aug 11 '11 at 11:11
1

You could try WCF data services, which can feed json i believe. it has an api for 'continuations' which are effectively paged queries. It might feel a bit strange for you to use this as a wrapper, but I'm sure you could make it work.

http://blogs.msdn.com/b/writingdata_services/archive/2011/02/25/getting-json-out-of-wcf-data-services.aspx

user381624
  • 676
  • 1
  • 5
  • 21
  • Thanks for the ideas. However, I am writing a client-side Silverlight application for an existing server-side API (that I do not host). I don't really want to add my own server-side component to support my application! – ColinE Aug 09 '11 at 12:21
  • This is conceptually no different to RIA services, which you are still considering? – user381624 Aug 09 '11 at 12:44
  • I have +1 your answer, yes, I misunderstood your response. I thought it required that I wrap the service which I am using within my own server-side component. – ColinE Aug 09 '11 at 13:13
  • Well, yes it could be implemented by wrapping it in a server side service, and to be honest, I was thinking server side. The client side API won't help much, except as a guide perhaps. The way it is done on the client is simple and cute, each time you get a 'page' of results, you also get a URL for the next page of results..... The other reason you might like a server side solution is for cross-domain reasons. Are you able to put a x-domain policy file on the server hosting your JSON service? If not, perhaps you need a server side wrapper regardless. – user381624 Aug 11 '11 at 06:14