Skip to content

Instantly share code, notes, and snippets.

@dmccreary
Last active January 29, 2020 14:55
Show Gist options
  • Save dmccreary/33a1cfce7cad4a583932 to your computer and use it in GitHub Desktop.
Save dmccreary/33a1cfce7cad4a583932 to your computer and use it in GitHub Desktop.
XForms table pagination with Orbeon. In this example the Prev and Next buttons are disable by binding rules.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<title>XForms 2 Row Repeat Test Using nodeset and id for Repeat</title>
<xf:model>
<xf:instance xmlns="" id="save-data">
<data>
<row>
<first-name>Dan</first-name>
<last-name>McCreary</last-name>
<phone-ext>111</phone-ext>
</row>
<row>
<first-name>Ann</first-name>
<last-name>Kelly</last-name>
<phone-ext>222</phone-ext>
</row>
<row>
<first-name>John</first-name>
<last-name>Anderson</last-name>
<phone-ext>333</phone-ext>
</row>
<row>
<first-name>Peg</first-name>
<last-name>Jones</last-name>
<phone-ext>444</phone-ext>
</row>
<row>
<first-name>Sue</first-name>
<last-name>Johnson</last-name>
<phone-ext>555</phone-ext>
</row>
<row>
<first-name>Fred</first-name>
<last-name>Smith</last-name>
<phone-ext>666</phone-ext>
</row>
<row>
<first-name>Bruno</first-name>
<last-name>Redstone</last-name>
<phone-ext>777</phone-ext>
</row>
<row>
<first-name>Sam</first-name>
<last-name>Lister</last-name>
<phone-ext>888</phone-ext>
</row>
<row>
<first-name>June</first-name>
<last-name>Table</last-name>
<phone-ext>999</phone-ext>
</row>
<row>
<first-name>Mary</first-name>
<last-name>Maker</last-name>
<phone-ext>10</phone-ext>
</row>
<row>
<first-name>Laura</first-name>
<last-name>Logan</last-name>
<phone-ext>11</phone-ext>
</row>
</data>
</xf:instance>
<!-- c is for pagination Counters s=start, e=end, n=number of items in a page -->
<xf:instance id="c" xmlns="">
<data>
<s>1</s>
<e>5</e>
<n>5</n>
</data>
</xf:instance>
<xf:instance id="views" xmlns="">
<data>
<prev/>
<next/>
</data>
</xf:instance>
<!-- mark the previous button as read only if the start is less then or equal to n -->
<xf:bind ref="instance('views')/prev" readonly="xs:decimal(instance('c')/s) le xs:decimal(instance('c')/n)"/>
<!-- mark the next button as read only if the start plus n is greater than the number of rows -->
<xf:bind ref="instance('views')/next" readonly="xs:decimal(instance('c')/s + xs:decimal(instance('c')/n)) gt count(instance('save-data')/row)"/>
</xf:model>
<style type="text/css"><![CDATA[
table thead tr th {background-color:silver;font-weight: bold;text-align:center;}
.orbeon .xforms-label {display: inline-block;}
.orbeon .xforms-label {font-weight: bold;}
]]></style>
</head>
<body>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<xf:repeat nodeset="instance('save-data')/row[position() ge xs:integer(instance('c')/s) and position() le xs:integer(instance('c')/e)]" id="r">
<tr>
<td><xf:output ref="count(./preceding-sibling::row) + 1"/></td>
<td><xf:input ref="./first-name"/></td>
<td><xf:input ref="./last-name"/></td>
<td><xf:input ref="./phone-ext"/></td>
</tr>
</xf:repeat>
</tbody>
</table>
<!-- disable trigger if start is less then n -->
<xf:trigger ref="instance('views')/prev">
<xf:label>Previous <xf:output ref="instance('c')/n"/></xf:label>
<!-- you can add this attribute if you do not disable the button with a binding rule
if="xs:decimal(instance('c')/s) gt xs:decimal(instance('c')/n)" -->
<xf:action ev:event="DOMActivate" >
<xf:setvalue ref="instance('c')/s" value="instance('c')/s - instance('c')/n"/>
<xf:setvalue ref="instance('c')/e" value="instance('c')/e - instance('c')/n"/>
</xf:action>
</xf:trigger>
<!-- disable trigger s + n less then or equal to row count -->
<!-- you can add this attribute if you do not disable the button with a binding rule
if="xs:decimal(instance('c')/s + xs:decimal(instance('c')/n)) le count(instance('save-data')/row)" -->
<xf:trigger ref="instance('views')/next">
<xf:label>Next <xf:output ref="instance('c')/n"/></xf:label>
<xf:action ev:event="DOMActivate" >
<xf:setvalue ref="instance('c')/s" value="instance('c')/s + instance('c')/n"/>
<xf:setvalue ref="instance('c')/e" value="instance('c')/e + instance('c')/n"/>
</xf:action>
</xf:trigger>
<xf:output ref="instance('c')/s">
<xf:label>Start=</xf:label>
</xf:output>
<xf:output ref="instance('c')/e">
<xf:label>End=</xf:label>
</xf:output>
<xf:output ref="instance('c')/n">
<xf:label>Number=</xf:label>
</xf:output>
<xf:output ref="count(instance('save-data')/row)">
<xf:label>Rows=</xf:label>
</xf:output>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment