jquery - passing datatable page number to webservice -


i'm working datatables , jquery.

i populating table result of web service. web service needs have limit clause in associated query there many results page takes long load.

so goal use page numbers in webservice call where:

if click page 2, posting 20,40 limit, if click page 3 posting 30,50.

so the:

page number clicked * 10 starting range , page number clicked * 10 + 20 finishing range of limit clause.

however pagenumbers displayed based on number of results, , if post webservice limit of 0,20 there 20 results , page numbers @ bottom of table not have 2,3,4 etc. options 20 rows returned.

is there way around this?

is there better way of implementing want achieve?

some code:

$(document).ready(function() {    tableallocation('<?php echo $_session['authcode']?>');     $('#table_id').datatable( {     "pagelength" : "20",     "order": [[ 0, "asc" ],[1, "asc"]]     });  }); 

where table allocation js function calls webservice , parses response populate datatable

there ready-made solution easy implement. handles trivials such limit, ordering, paging etc out of box. below mysql, there made similar solutions long range of databases , architectures.

1) goto https://legacy.datatables.net/examples/data_sources/server_side.html , copy "server side (php) code" file, can call datatables.php

2) edit datatables.php credentials :

$gasql['user']       = "user";   $gasql['password']   = "password";   $gasql['db']         = "database";   $gasql['server']     = "localhost";   

3) configure datatables.php table , column settings :

the table name

$stable = "database table";   

which columns show

$acolumns = array( 'column1', 'column2' ... ); 

specify index column, this important!

$sindexcolumn = "index column"; 

the index column not have included in $acolumns.

4) build markup

<table id="example"> <thead>     <tr>         <th>column1</th>         <th>column2</th>     </tr> </thead> <tbody> </tbody> </table> 

5) create datatable serverside driven datatable using datatables.php :

$('#example').datatable({     bprocessing: true,     bserverside: true,     sajaxsource: "datatables.php" }); 

the above solution works both 1.9.x , 1.10.x datatables versions / branches.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -