Friday, November 19, 2010

Pagination for joint DVWP

As you might see, in sharepoint 2007 and in par with in sharepoint 2010 follow the same method on pagination for the joint list DVWP. If you add a single list, to DVWP and add pagination value, it normally works as expected. But once you link the existing datasource with another list, it automatically removes the pagination from the rendering part, still it keeps the xsl tags in the back-end. So how to enable the out of the box pagination.
Lets say "Category" List and "SubCategory" Lists are there. You are showing Sub Categories for the given Category. But all happens through the webpart. No addition of content type in page layout (Client requirement as they want to use the same layout for different purpose). If you link Category and SubCategory, pagination disappears. so you can't limit the number of SubCategories showing in webpart. In order to resolve that issue...
Obviously you can't enable the pagination by switching on and off, where as you have to write the xsl for the <xsl:template name="dvt_1.commandfooter"> template.
The parameters for the commandfooter template will be the same as default

<xsl:call-template name="dvt_1.commandfooter">
  <xsl:with-param name="FirstRow" select="$FirstRow" />
  <xsl:with-param name="LastRow" select="$LastRow" />
  <xsl:with-param name="RowLimit" select="$RowLimit" />
  <xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" />
  <xsl:with-param name="RealLastRow" select="number(ddwrt:NameChanged('',-100))" />
</xsl:call-template>

and the template will be implemented like this

<xsl:template name="dvt_1.commandfooter">
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:param name="RowLimit" />
<xsl:param name="dvt_RowCount" />
<xsl:param name="RealLastRow" />
<xsl:variable name="preNumber" select="$FirstRow - $RowLimit" />
<xsl:variable name="nextNumber" select="$FirstRow + $RowLimit" />
<table><tbody><tr>
<xsl:if test="$FirstRow > 1">

</xsl:if><td>
<a href="/test1.aspx?PageLimit=$preNumber">Pre</a>
</td>

<xsl:if test="$nextNumber <= $dvt_RowCount">
</xsl:if><td>
<a href="/test1.aspx?PageLimit=$nextNumber">Next</a>
</td>
</tr>
</tbody></table>
</ xsl:template>

the parameter binding will be added with one more data as follows

<parameterbinding name="PageLimit" location="QueryString(PLimit)" defaultvalue="1" />

This is to limit the number of rows on the second list of joint view.
Assign the variables as follows

<xsl:variable name="FirstRow" select="$PageLimit" />
<xsl:variable name="LastRow" select="$FirstRow + $RowLimit" />

Call the body as follows

<xsl:call-template name="dvt_1.body">
  <xsl:with-param name="RowLimit" select="$RowLimit" />
  <xsl:with-param name="Rows" select="$Rows" />
  <xsl:with-param name="FirstRow" select="$FirstRow" />
  <xsl:with-param name="LastRow" select="$FirstRow + $RowLimit - 1" />
</xsl:call-template>

Now you are done with your pagination


P.S: This is my first blog post. Add your comments. :)

No comments:

Post a Comment