Hi!
I would like to realize a little component for my web2py app to load some data I got in arrays (lists or dictionaries) in tables , in this way, always coherent throug the site. I thought to use the jQuery dataTable class but a little after I thought that it would be nice to use the same style I got in SQLTABLE.grid I use per data that comes from database. Any Idea how to do it?
Here I copy the code I started to develop for example:

controllers/services.py

def dataTable():
    jqInfo = request.vars.jqInfo
    aaData = request.vars.aaData
    if type(aaData)==dict:
        aaData = aaData.items()
    return dict(jqInfo=jqInfo, aaData=aaData)

## in this example jqinfo is not used. I intended to use it to write the parameters such as bFilter, bSort etc.

views/services/dataTable.load

{{=SCRIPT('''$(document).ready(function() {
    $('#dataTable').dataTable( {
    "bFilter": false,
    "bSort": false,
    "bInfo": false,
    "bProcessing": true,
    "bAutoWidth": false
    } );
} );''', _type="text/javascript", _charset="utf-8")}}

{{head = THEAD(TR(*[TH('', _width='20%') for i in range(len(aaData[0]))]))}}

<table cellpadding="0" cellspacing="0" border="0" class="display" id="dataTable">
    {{=head}}
<tbody>
        {{for r in aaData:}}
<tr>
            {{for c in r:}}
                {{=TD(c)}}
            {{pass}}
</tr>
        {{pass}}
</tbody>
</table>

and here is an axample how to call this component inside a page view:

{{response.files.append(URL(r=request,c='static',f='js/DataTables-1.8.2/media/js/jquery.js'))}}
{{response.files.append(URL(r=request,c='static',f='js/DataTables-1.8.2/media/js/jquery.dataTables.js'))}}
{{response.files.append(URL(r=request,c='static',f='js/DataTables-1.8.2/media/css/demo_page.css'))}}
{{response.files.append(URL(r=request,c='static',f='js/DataTables-1.8.2/media/css/demo_table.css'))}}
{{extend 'layout.html'}}
[...]

{{=LOAD('services', 'dataTable2.load', vars=dict(aaData=myDataArray))}}

Reply via email to