28 May 2005
Adding page numbers to a paged Data View web part
I found it hard to believe that no one had posted something on this already...
I think I have heard it grumbled now and again - it's nice that SharePoint Lists support paging - but where are the individual page numbers? why do I have to click Next, Next, Next!!!
I can now end this misery and winging by adding page numbers to Data Views.
The solution leverages the fact that the navigation links created by default pass a parameter indicating what row number to start rendering from. By looping through the row data and checking the current position we can simply output a page number ( ((position() - 1) div $RowLimit) + 1) ) everytime we get to a row number that would be the start of the next page ( using position() mod $RowLimit ). I am not sure how efficient it is - happy to accept feedback on your experiences... this is just a sample - who knows how well it will work against your 10,000 rows of data :)
This solution assumes you have created a Data View and changed its options to "Display items in sets of this size X"
To implement:
1. Using FrontPage 2003, view the HTML (XSLT) source of your Data View
2. Find <xsl:template name="dvt_1.navigation"> and add <xsl:param name="Rows"/> as the last param
3. Somewhere in the <table> that is output in this template
<tr><td colspan="2" class="ms-vb">
<xsl:for-each select="$Rows">
<xsl:if test="(position() mod $RowLimit) = 1">
<a>
<xsl:attribute name="href">javascript: <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',position(),'}'))"/>;</xsl:attribute>
<xsl:value-of select="((position() - 1) div $RowLimit) + 1"/></a>
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</xsl:if>
</xsl:for-each>
</td></tr>
4. Find <xsl:call-template name="dvt_1.navigation"> and add <xsl:with-param name="Rows" select="$Rows"/> as the last param
This should be enough to get you started. You could add an <xsl:if test> statement to prevent the current page number from being created as a link.