web2py pagination

66 views
Skip to first unread message

Maurice Waka

unread,
Jan 26, 2015, 9:30:25 AM1/26/15
to web...@googlegroups.com
Suppose I have such a code:

def products():
  if len(request.args): page=int(request.args[0])
  else: page=0
  items_per_page=20
  limitby=(page*items_per_page,(page+1)*(items_per_page+1))
  qset = db(db['products']['name']!='None')
  grid = qset.select(limitby=limitby)
  return dict(grid=grid,page=page,items_per_page=items_per_page)

My view:

{{extend 'layout.html'}}
<h2>Browse available products:</h2>

<table class="products">
{{for i, row in enumerate(grid):}}
{{if i==items_per_page:break}}
<tr>
<td>{{=row.name}}</td>
{{pass}}
</tr>
</table>

{{if page:}}
<a href="{{=URL(args=[page-1])}}">previous</a>
{{pass}}

{{if len(grid)>items_per_page:}}
<a href="{{=URL(args=[page+1])}}">next</a>
{{pass}}

I have 'next' button and 'previous' button. How do I get the 'last' button(page with the last items on the list?
Regards

Cássio Botaro

unread,
Jan 26, 2015, 1:09:07 PM1/26/15
to web...@googlegroups.com
An example: http://mindbending.org/pt/paginando-consultas-web2py
unfortunately in portuguese, but the code is clear.

Reply all
Reply to author
Forward
0 new messages