wiki:ServerSidePagination

Version 23 (modified by Fran Boon, 12 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

Status

  • The Back-end is now done for HTML representation
  • The Back-end was already done for JSON representation
  • The Front-end still needs doing

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
iSortCol_0
iSortingCols
iSortCol_x
iSortDir_x
# Filtering (Search) - across all fields!
sSearch

response should be sent in tbhis format:

aaData": [
    [row1.field1.value, row1.field2.value, row1.field3.value],
    [row2.field1.value, row2.field2.value, row2.field3.value]
]

e.g. using a function like:

def callback():
    print request.vars
    from gluon.serializers import json
    query = ....
    rows = db(query).select() #<<<
    r=dict(rEcho=1,
           iTotalRecords=len(rows),
           iTotalDisplayRecords=len(rows),
           aaData=[[row.field1,row.field2] for row in rows])
    return json(r)

If you print request.vars you can easy figure out what paramers are being passed and change the <<< line accordingly.

JSON Back-end implementation

  • Support already present in modules\s3xrc.py
    • 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"])
    else:
        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"])
    else:
        limit = None
    
  • actually needs a complete new representation!

HTML Back-end implementation

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

shn_list()
...
     if request.vars.limit:
        limit = int(request.vars.limit)
        if request.vars.start:
            start = int(request.vars.start)
            limitby = (start, start + limit)
        else:
            limitby = (0, limit)
    else:
        limitby = None
...
items = crud.select(table, query=query,
            ...
            limitby=limitby, 
            ...
            )

Other Options

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

Haiti

Note: See TracWiki for help on using the wiki.