Version 35 (modified by Fran Boon, 14 years ago) ( diff )


Server-Side Pagination

Currently we do all pagination client-side which won't be possible to keep doing as we accumulate more data

This will be needed for:

fractalis has offered to look at this


  • The Back-end is now done for HTML representation
  • The Back-end was already done for JSON representation, now done in the dataTables way
  • The Front-end is done: 50 records at a time :)
  • ToDo:
    • Push from Dev to Live
    • Render as .represent
    • Return to Live (1 line in Controller functions: response.s3.pagination = True)
    • Sort Columns (orderby)
    • Search (filtering)
    • XSLT to generate dataTables-compliant JSON?

Front-end implementation

Client-side, we need to add these options to views/dataTables.html [make them Optional per-REST Controller?]:

    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "{{=URL(r=request, c='module', r='resource', vars={'...':'...'})}}"

Server-side, we need to understand these vars:

# Pagination
iDisplayStart - maps to 'start'
iDisplayLength - maps to 'limit'
# Ordering
# Filtering (Search) - across all fields!

response should be sent in this format:

"sEcho": 1,
"aaData": [
    [, row1.field2, ...],
    [, row2.field2, ...],
    [, row3.field2, ...]
"iTotalRecords": 3,
"iTotalDisplayRecords": 3

e.g. using a function like (although we've integarted into models/

def callback():
    iDisplayStart = int(request.vars.iDisplayStart)
    iDisplayLength = int(request.vars.iDisplayLength)
    from gluon.serializers import json
    _table = '%s_%s' % (request.controller, request.function)
    table = db[_table]
    query = ( > 0)
    rows = db(query).select(limitby = (iDisplayStart, iDisplayStart + iDisplayLength))
    r = dict(sEcho = 1,
           iTotalRecords = len(rows),
           iTotalDisplayRecords = len(rows),
           aaData = [[row[f] for f in table.fields if table[f].readable] for row in rows])
    return json(r)


JSON Back-end implementation

  • Support already present in modules\
    • http://S3_PUBLIC_URL/module/resource.json?limit=x&start=y
  • needs patching for dataTables-expectations:
    if "start" in self.request.vars:
        start = int(self.request.vars["start"])
    elif "iDisplayStart" in self.request.vars:
        # dataTables
        start = int(self.request.vars["iDisplayStart"])
        start = None
    if "limit" in self.request.vars:
        limit = int(self.request.vars["limit"])
    elif "iDisplayLength" in self.request.vars:
        # dataTables
        limit = int(self.request.vars["iDisplayLength"])
        limit = None
  • actually needs a complete new representation unless this could be done via XSLT!?
    • still needs extension adding to shn_xml_export_formats in models\

HTML Back-end implementation

Patched the models\01_RESTlike_Controller to support http://S3_PUBLIC_URL/module/resource?limit=x&start=y

     if request.vars.limit:
        limit = int(request.vars.limit)
        if request.vars.start:
            start = int(request.vars.start)
            limitby = (start, start + limit)
            limitby = (0, limit)
        limitby = None
items =, query=query,

Other Options

  • Maybe look at the currently-unused modules/
  • pagenav in models\01_RESTlike_Controller seems unused currently...was an older implementation of a webgrid...can probably be removed.
  • ExtJS

Haiti Haiti

Note: See TracWiki for help on using the wiki.