I can't show you all the code because the property belongs to the person who asked me to do it,
This is the part that takes the dataables json requests, fetch the records and format them to be understood by datatables. I am skipping the sorting/filtering part , that builds the query_filter and orderby variables
I have also changed the table name by MY_TABLE and remove one field name.
Also, beware in this case the total number of records uses count(), you will have to replace it if your table has many records.
Hope it helps you.
José L.
@service.json
def logs_table():
query_filter = None
if request.vars.start is not None:
iDisplayStart = int(request.vars.start)
else:
iDisplayStart = 0
if request.vars.length is not None:
iDisplayLength = int(request.vars.length)
else:
iDisplayLength = 10
if request.vars.draw is not None:
sEcho = int(request.vars.draw)
else:
sEcho = 1
.... ....
query = db(query_filter).select(db.MY_TABLE.ALL,
limitby=(iDisplayStart, iDisplayStart + iDisplayLength),
orderby=orderby)
iTotalRecords = db(query_filter).count()
# iTotalRecords = 1000000
aaData = []
for row in query:
datarow = {}
for col in row:
if row[col] is not None:
if col == 'MY_TABLE' or '_record' in col:
# internal dal col names
continue
elif col == 'name of field that is a datetime':
datarow[col] = row[col].strftime('%Y-%m-%d %H:%M:%S')
else:
datarow[col] = row[col]
else:
datarow[col] = ''
aaData.append(datarow)
return dict(draw=sEcho, recordsTotal=iTotalRecords, recordsFiltered=iTotalRecords, data=aaData)