Tuesday, October 13, 2009

Silverlight Data Pagination without knowing the page count

I had a typical situation today where i need to write my own custom silverlight data pager control which
1) needs to speak to my web services to fetch incremental data. i.e. each page click should send a request to the web service.

2)** The services were not in my control . All i get is data if i pass start & end index to the service.

Breif info on existing silverlight pager controls

1) the one that comes with silverlight toolkit is a client side one.So its more of a fetch all data & distribute among pages approach which i dont want.

2)Some custom pagers which fetch data from services on every page click.But these paging controls needs to have the page count before hand to build the pager & display the number of pages.

But in my case
I dont want client side pager.
I dont know the total records count before hand so i cant tell you the number of pages.

So How i go about hsi problem
- All that i have is 2 buttons 'Previous' & 'Next' Button.

How the logic works here

1) first disable previous & next buttons
2)fetch double the pagesize. say if ur page size is 20 then go & fetch (0,40) records.
On fetch if count of records < pagesize in our case 20 then disable next button.

if fetched records count > 20 then enable next button.

The logic has some checks & all we do at end of each page fetch is adding those records to a pagedcollectionview. So ur back button press is a offline query to the collection that you hold.Even though this kind of an approach saves ur web service request hits its not recommended.Because all we are interested is 'LIVE' Data.

Anyways i will be posting a custom pager in the next few days once i am done.