Recently I worked for a requirement with my collegue Ankur Chourasia on consolidating the information from the sub sites and displaying it on the main site using Content Query Web Part. I consider that as the first part of this post. Please make sure to go through “A Little More about Content Query Web Part“. The consolidation and additional column displaying part is done by Ankur Chourasia and he did it fantastically. I will surely encourage him to add that onto his blog site.
There was another interesting requirement where in the user wanted the table data to be sorted. Just like we do in any other SharePoint lists, again my love jQuery came onto picture and we could achieve the sorting table functionality.
I found it worth putting down on paper and sharing. Comments welcome J
Table Sorter Plug-in
Here is the final structure of my files.
o Other gif files
è tablesort.html (this contains the jquery code)
The table sorter plug in looks out for all the <table> tag which contains the “class=tablesorter” attribute. Other requirement is that the table columns should be inside the <thead> element and table body should be inside the <tbody> element. For e.g.
ItemStyle.xsl template modification
Here is the modified template in the ItemStyle.xsl file to achieve the required html output. Notice the class attribute of <table> element the <thead> and <tbody> elements.
Enabling sorting on the CQWP tables
– Upload the modified ItemStyle.xsl file onto Style Library.
– Navigate to the page where you have added the Content Query Web Part.
– Add a Content Editor Web Part. Edit the web part and set the Content Link property to URL of “TableSort.html” file in the Shared Documents library (e.g yoursitedocumentstableSort.html).
Tip: You can keep this content editor web part as hidden, the jquery code to enable sorting will still work.
– This will make the column heading clickable. Clicking on the column heading will sort the rows of the table.
I hope this helps some one in need. I sincerely like to thank Ankur Chourasia and Christian Bach