Introduction
In this post I will try to show you how to implement a simple paging mechanism using InfoPath 2010. This approach is useful if you are considering a quick & fast solution to handle InfoPath Repeating Tables (or sections) that returns 100s of items without writing code behind and by following few simple steps.
How to do it:
In this scenario I already have an InfoPath Form that has a sample Repeating Table that returns more than 300 items. I would like to configure it to show a 100 item on each page, below are the steps:
1- Add a new field on you Main Data Source as following:
2- Add 2 new buttons on the form to handle Previous & Next Pages:
3- In the InfoPath Repeating Table (or Section) add a new column and inset a new Calculated Value Control from the Controls Ribbon. This Calculated Value will hold the Row Number of the data that you retrieve:
4- Open the newly added Calculated Value Property and update your Data Source using the Position() XPath:
5- Create a Rule for the Previous Page Button on Click as following:
Rule Name: Previous Rule
Condition: PageNumber != 1
Action: Set Fields Value of PageNumber = PageNumber - 1
6- Create a Rule for the Next Page Button on Click as following:
Rule Name: Next Rule
Condition: PageNumber<= Count(ID) / 100
Action: Set Fields Value of PageNumber = PageNumber + 1
Note:
- Whenever you see the number 100 it represents the page size.
- you can select any fields with the Count() function, in this scenario I used ID field.
7- Now the Tricky Part ... you need to create 2 new Formatting Rules on the Repeating Table as following:
Rule Name: Hide Rule 1
Condition (Expression): position() >= 100 * xdXDocument:get-DOM()/my:myFields/my:PageNumber
Check on: Hide this Control
Rule Name: Hide Rule 2
Condition (Expression): position() < 100 * (xdXDocument:get-DOM()/my:myFields/my:PageNumber - 1)
Check on: Hide this Control
And that all folks ... Run your form and start Paging :)