Some of the information here may be outdated, please check the book instead

Based on :

This example improves on the previous one by calculating the total number of records beforehand.

It provides positional feedback to the user, and avoids displaying an empty list at the end.

def show_records():
    totalrecs = db.executesql('select count(*) from table')[0][0]  # number of records in table (for example)
    showlines = 25       # number of records per page
    if len(request.args):
       page=0>0 ### for example (all records in table)
    backward=A('<< previous',_href=URL(r=request,args=[page-showlines])) if page else '<< previous'
    forward=A('next >>',_href=URL(r=request,args=[page+showlines])) if totalrecs>page+showlines else 'next >>'
    nav= "Showing %d to %d out of %d records"  % (page+1, page+len(rows), totalrecs)
    return dict(rows=rows,backward=backward,forward=forward, nav=nav)
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.