Datatables and "slow" Ajax sourced data...

Datatables and "slow" Ajax sourced data...

FireFoxIIFireFoxII Posts: 17Questions: 10Answers: 0

I'm using datatable script to fill a table of large number of rows...

Call to datatable and jquery was like this

<table id="table" class="table table-bordered table-striped">
 <thead>
  <tr>
    <th>column 1</th>
    <th>column 2</th>
  </tr>
 </thead>
</table>

$(document).ready(function() {
    $('#example').DataTable( {
        "ajax": 'script.php'
    } );
} );

And this is a sample of SCRIPT.PHP to read data from a mysql database

$data = array();

$sql = "SELECT a, b FROM database";
$res = $db->query($sql);
while ($f = $res->fetch()) {
  $nestedData=array(); 
  $nestedData[] = $f['a'];
  $nestedData[] = $f['b'];
  $data[] = $nestedData;
}
$json_data = array( "data" => $data );
echo json_encode($json_data);

The PROBLEM was that in this way I must attend loading of data from database (on large db, the wait was very long) and then the tables was filled, but I want to fill data for each row read from database...

How is this possibile?

Answers

This discussion has been closed.