"Max. Records" Coherence Suggestion explained with sample

"Max. Records" Coherence Suggestion explained with sample

  
For performance reasons, when populating a Table Record widget with information from a database, you should only query the necessary amount of lines (or rows). This is the reason for the existence of the "Max. Records" property in Queries.

Let us assume we want to implement a multi-screen Table display, with "Previous" and "Next" functionality.
It becomes apparent that, for any one screen of the table, you should need only query the first StartLine+MaxTableLineCount records. As an example, if your table only displays 4 lines per screen, your would have:

- 1st screen:
Displays records 0 to 3
We only require the first 4 records for this display, because StartLine=0 + MaxTableLineCount=4

- 2nd screen:
Displays records 4 to 7
We only require the first 8 records for this display, because StartLine=4 + MaxTableLineCount=4
(remember you always have to query from the first record, you cannot query from record 4 onwards)

- 3rd screen:
Displays records 8 to 1
We only require the first 12 records for this display, because StartLine=8 + MaxTableLineCount=4

..And so on.

With this in mind, we would assume that (in the sample eSpace attached to this post) the "Max. Records" property is correctly set to "StartLine + TableRecords.LineCount". However if you validate the eSpace you get the following warning:

Coherence Suggestion: Query1 'Max. Records' should be set to 'StartLine+TableRecords.LineCount+1' to match the number of records presented by TableRecords.

Why is this the case? Why the "+1"?

Strictly speaking, to display our required number or rows we really only need "StartLine + TableRecords.LineCount" lines. However, we normally want to have enough information to allow us to display a "Next" Link (or Button), if the current iteration of the table (the current screen) has not exhausted our data. Because of this we need to read one more record to determine, via the RecordList’s EOF, if we indeed reached the end.

Ignore the Verification warning for now and Compile and Publish the eSpace anyway. Then create the seed data (made up of 8 rows) by going through the "SeedData" entry point first. Now test the main entry point: the "Next" is not clickable!

Looking at the condition in the rightmost If widget (in WebScreen1) that determines the appearance of a link in the "Next" text, we see "not TableRecords.List.EOF". This is correct, but "TableRecords.List.EOF" will always be true if we displayed up to the very last record/line in the ListRecord that feeds the Table Record widget.

Now go to TestEntityQuery in WebScreen1's Preparation. Change "Max. Records" to the suggested "StartLine + TableRecords.LineCount + 1", 1CP and test the main entry point. Now the "Next" link works, because we are now able to detect the real EOF (i.e. when the Table Record exhausted all the database lines) rather than the RecordList's EOF (i.e. because the Table Record exhausted all the lines we queried this time).