For usability and performance reasons, it is convenient to display grid results in a fixed-size grid and provide buttons to browse the pages (Grid paging).
Paging applies to Grids and Free Style Grids, as well as to nested grids.
Paging can be automatic or manual, when the grid Rows property has a value other than zero.
For manual paging, you have methods associated with the Grid control.
Below are the methods available to handle manual paging:
The FirstPage method takes the user to the first set of returned records. For example, in the code below, when the user clicks on the button associated with the Enter event, the first set of records will be displayed in the grid.
The NextPage method displays the set of records that follow.
&err = MyGrid.NextPage()
if &err = 2
Message.Caption = 'Last page already displayed'
In this example, when the user clicks on the NextList button, the Grid will display the set of records that follow. If the last page is already loaded, the message "Last page already displayed" will be shown in the Message text block.
The PreviousPage method displays the previous set of records.
&err = MyGrid.PreviousPage()
if &err = 2
Message.Caption = ‘First page already displayed’
In this example, when the user clicks on the BackList button, the Grid will show the previous set of records. If the first page is already loaded, the "First page already displayed" message will be displayed in the Message textblock.
The LastPage method takes the user to the last set of records. It can be used only if the grid has a base table.
In this example, when the user clicks on the Last button, the grid will display the last set of records.
The GotoPage(PageNumber) method gives direct access to a particular set of records. It can be used only if the grid has a base table. The following example shows a call to the page corresponding to a set of data.
Methods return a value after execution.
- 0: Successful operation.
- 1: Grid paging is not enabled.
- 2: Last page already displayed or First page already displayed (according to the NextPage or PreviousPage method, respectively).
- 3: The grid doesn't have a base table.
- If paging is applied to a web panel that has filters, the FirstPage method should be used in the event that applies the filter so as not to display the result corresponding to the previous page.
- The efficiency of the FirstPage, NextPage, PreviousPage and GotoPage(N) methods is related to the efficiency of the navigation defined for the corresponding Grid. In other words, if the grid has good response times without paging, the response times with paging will be similar.
Consider that Server Paging is used when it's possible: when any of the conditions used to navigate the Grid (Where conditions) is evaluated in the client, Server Paging optimization is not performed.
- The RecordCount, LastPage, and GotPage methods are not implemented for Grids without a Base Table, or Grids that have a Base table but any of their conditions are evaluated on the client side (cannot be evaluated by the DBMS).
When Server Paging cannot be used, Paging is done per "record number". To show page N, the records in previous pages (N-1) are read without being displayed.
- Having good data filtering (so that there aren't many pages).
- Avoiding, when the cost is high, the use of GotoPage(N) with high N values, as well as the use of LastPage.
- Saving the value of the RecordCount property in a variable, since each call to the property implies a COUNT in the database.