Data Tables Server Side loading all results
Data Tables Server Side loading all results
Neworld
Posts: 5Questions: 0Answers: 0
Hi all,
I have followed the exact instructions that you are giving on the page https://datatables.net/examples/server_side/simple.html and what happens is that is loading all results instead of loading de default amount (10 entries I believe).
Any Idea why is happening this?
This discussion has been closed.
Replies
The example works correctly, so you must have some differences in your own code. Without seeing your code, I have no idea what the difference is.
Hi tangerine,
thanks for the quick response,
here the code
HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>DataTables Server-side processing</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
</head>
<body class="wide comments example">
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "./js/list.php"
} );
} );
</script>
</body>
</html>
list.php simply echos the AJAX data You are providing
That's where you're going wrong. The AJAX data is showing you what is returned by the server-side processing script, which you have omitted. The data is requested from the database and returned formatted as JSON for display by DataTables. You have completely skipped the database inter-activity.
Ho. Got IT.
It is working now.
But still have one question. I realized that it's being used $_GET vars to send info to query the Data Base.
Is there a way to know what variables are sent to query?
Thank You!!!
https://datatables.net/manual/server-side
Ok. I've read it but what I actually need is to change add WHERE a = 1 to the query.
Lep me explain:
I am getting this result
Array
(
[0] => 1
[1] => 1500426082
[2] => Something
[3] => 123456-2015
[4] => 3
[5] => 2017-07-24 05:41:55
[8] => 2017-07-21 05:18:13
)
And I want to replace the value of array 4 with the name of row 3 from a different table.
Any Ideas?
Thank You Al!!!
My solution, if I understand your issue right, is to add column definitions
By doint this, the name of each search value can be associated with a name in the database.
Basically the values of array 4 is the ID of another table.
What I need to do is run another query in a different table and replace the 3 with another field from the second query.
I don't know if I am clear.
That's probably not necessary. You need to revise your existing query to incorporate a join to the second table.