Reloading a Collection in the PivotViewer

I discovered an interesting tidbit when working on the code for my upcoming PivotViewer series (you can find the code on CodePlex here : http://tonyc.me/pvles).  It seems that you can’t reload the current collection from the server.

First off, I noticed an absence of any sort of “Reload” or “Refresh” method to make this process easy.  So I began to do a little research and tried the following:

To begin with, I simply called LoadCollection() and passed in the Uri.  I promptly noticed that nothing happened. Hmmm… So on to the next step.

If you are familiar with the LoadCollection() method, then you might have noticed a default viewerState as the second argument.  The viewer state is a lot of fun and I will dig into that in another post.  However, for this issue, I was hoping changing up the viewer state would fire off a refresh.  Nope.  Strike two.

So now I decided to bring out the big guns, .Net Reflector by Red-Gate, to see if I could see what is going on.  By the way, it’s a great tool to have as a .Net developer and I highly recommend it.  So I did a little digging, and what do you know, I found the issue.

The PivotViewer is simply trying to be efficient really.  When you pass in a Uri, it compares it with the existing collection to see if it is the same.  If it is, it simply does not do a reload to keep from having to make another trip to the server to update the data and interrupt the user’s experience.

Ah ha! So now we just need to change the Uri, right?  My first attempt was to simply add a hash tag with a counter.  So my attempts looked something like this:

First attempt:

http://mycollection/collection.cxml

Second attempt:

http://mycollection/collection.cxml#reload1

Well, it seems that the PivotViewer was smarter than me and realized it was the same Uri and ignored the new Uri.  So I took it a step further and found a working solution.  It seems that it will consider a change in the querystring as a new Uri.  So the final working solution looks like this:

First attempt:

http://mycollection/collection.cxml

Second attempt:

http://mycollection/collection.cxml?reload=1

Bingo! I nice reloaded collection.

If you find yourself needing to refresh the collection of the PivotViewer and can’t seem to make it refresh, then this should get you up and running.

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *

.NET development is constantly changing and expanding. With over 20 years in the industry, I have had the opportunity to see this the technology and the community grow and shift. To get weekly updates and insights into the world of .NET, development, and career advancement click the subscribe button.