I recently implemented a pivot table widget at work and it was mostly based on your code.
It was a while ago, but I remember it worked with very few changes.