Richard,
Here is my minimal code for returning json data in dataTables via
web2py's ajax function.
---View---
<!-- here's a well-formed table -->
<table id="abc_table">
<thead>
<tr>
<th>ABC Category Name</th>
<th>Code</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
// this I keep in js folder
function dtbl_show(hash_div, sAjaxSource, aoColumns) {
$(document).ready(function() {
$(hash_div).dataTable( {
"bJQueryUI": true,
"bDeferRender": true,
"bPaginate": true,
'sPaginationType': 'full_numbers',
"bProcessing": true,
"bServerSide": true,
"aaSorting": [[ 1, "desc" ]],
"bAutoWidth": false,
"aoColumns" : aoColumns,
"sAjaxSource": sAjaxSource
} );
} );
jQuery.fn.dataTableExt.oPagination.iFullNumbersShowPages = 10;
}
</script>
<script>
// call here this script & pass the table's div for rendering it
dtbl_show("#abc_table", "{{=URL('abc','get_abcdata')}}", [{ sWidth:
'350px' }, { sWidth: '200px' }] )
</script>
--- End View ---
--- Controller for populating data via ajax ---
(excuse the bugged-up indentation here)
def get_abcdata():
if request_vars_iDisplayStart != None:
iDisplayStart = request_vars_iDisplayStart
else:
iDisplayStart = 0
if request_vars_iDisplayLength != None:
iDisplayLength = request_vars_iDisplayLength
else:
iDisplayLength = 10
if request_vars_sEcho != None:
sEcho = int(request_vars_sEcho)
else:
sEcho = 1
qry = 'your sql query string'
### Below this, I am using a 3rd party library viz. DABO for
interacting with DB.
### You may substitute that syntax with the DB layer of your choice
(DAL or whatever else) and get dataset.
try:
conn_name = connInstance.makeConn()
cur = conn_name.cursor()
qry = qry1 + ' limit ' + str(iDisplayStart) + ', ' +
str(iDisplayLength) + ';'
# fetch total data
cur.execute(qry1)
data_full = cur.getDataSet()
iTotalRecords = len(data_full)
# fetch data as requested from client
cur.execute(qry)
data_disp = cur.getDataSet()
iTotalDisplayRecords = len(data_full)
finally:
conn_name.close()
aaData = []
# Now populate the aaData with data in form of lists.
# e.g. aaDada will look like -- [[1, 'Vineet'],[2,'Richard']]
# This formatting is important
D=dict(sEcho=sEcho, iTotalRecords=iTotalRecords,
iTotalDisplayRecords=iTotalDisplayRecords,
iDisplayLength=iDisplayLength, aaData=aaData)
return response.json(D)
-- End of Controller code --
That's wraps it up.
If you need any further drilling down in my code, pl. ask.
I will be happy to share.
HTH,
--- Vineet
On Feb 8, 10:18 pm, Richard Vézina <[email protected]>
wrote:
> Yes!
>
> I think the PowerTable of Burno don't implement server side processing
> yet... We maybe can start form there to make a server side implementation
> of PowerTable... What do you think?
>
> I think, we have to split table header from data then wrote a python
> implementation fo the php script as shown in the example of DTs...
>
> For sure see a bit of your code could help me figure out the path I should
> follow and help my reflexion.
>
> About "fnInitComplete" it is just needed in case you want to initialise DTs
> with fixed columns...
>
> Richard
>
> On Wed, Feb 8, 2012 at 11:52 AM, Vineet <[email protected]> wrote:
> > Hi Richard !
> > Pl. excuse my late replying.
> > Glad to hear that you got it working.
>
> > If you are interested, I can share my code.
> > I am not using "fnInitComplete".
> > Mine is very simple & minimal code.
>
> > --- Vineet
>
> > On Feb 7, 10:19 pm, Richard Vézina <[email protected]>
> > wrote:
> > > Finally got it to work...
>
> > > There was a problem with the init of DTs particularly this option :
>
> > >http://datatables.net/release-datatables/extras/FixedColumns/server-s...
>
> > > *fnInitComplete*
> > > *
> > > *
> > > *
> > > *
> > > It's not solving my speed problem as I expect it could do... So I will
> > put
> > > it on hold, but I plan to implement a basic server interaction script as
> > > the php DTs example to make it easier deploy DTs with server side
> > > capability...
>
> > > Richard
>
> > > On Mon, Feb 6, 2012 at 6:10 PM, Bruno Rocha <[email protected]>
> > wrote:
> > > > Not,
>
> > > > PowerGrid is based in pure Jquery Templates
>
> > > > --
>
> > > > Bruno Rocha
> > > > [http://rochacbruno.com.br]
>
>