The Repeater component serves to display the same component repeatedly over a set of data defined by Repeater's data source. Note that unlike Tables, TreeTables, and Grids, Repeaters do not load their data source objects lazily.
Defining a Repeater
To create a Repeater with your content, do the following:
- Insert the Repeater component into your Form.
- In the Properties view of the Repeater, define its properties:
- Select the Vertical option to display the repeated content vertically: leave blank to display the components horizontally.
- Define the data source type and value.
- If applicable, change the data type of the iterator in the Type field next to the iterator name.
- Insert form components into the Repeater form: use the iterator name to work with the current data-source object.
Paging in Repeater
To implement paging in a Repeater, do the following:
- Set the required page size on the Repeater with
setPageSize()
- Set the required start index on the Repeater with
setStartIndex()
.
- Create a component, that will implement the next page functionality, for example, a Next button with a click listener:
{ e ->
//set new start index when the user clicks previous
myRepeater.setStartIndex(myRepeater.getStartIndex() + myRepeater.getPageSize());
myRepeater.refresh();
}
- Create a component, that will implement the previous page functionality, for example, a Next button with a click listener:
{ e ->
//set new start index when the user clicks previous
myRepeater.setStartIndex(myRepeater.getStartIndex() - myRepeater.getPageSize());
myRepeater.refresh();
}
- Create a form method that will disable and enable the next and previous page functionality when no more previous or next items are available:
private void refreshButtonEnabled() {
nextButton.setEnabled( myRepeater.getStartIndex() + myRepeater.getPageSize() < repeaterCollectionDs.size());
prevButton.setEnabled( not (myRepeater.getStartIndex() - myRepeater.getPageSize() < 0) );
}