Server side processing not displaying response data
Server side processing not displaying response data
aliemamhadi
Posts: 2Questions: 1Answers: 0
Hi,
i try to load some information from db to data table;
here is a js code:
var inbox_t = $('#dt-inbox').DataTable( {
"dom": '<"top"flp<"clear">>rt<"bottom"ip<"clear">>',
//"stateSave": true,
//"stateDuration": 60 * 60 * 24,
"processing": true,
"serverSide": true,
"ajax": {
"url": "../api/inbox.php",
"type": "GET",
"cache": false,
"data": function ( d ) {
d.token = token
},
"success":function(d){
console.log("data recieved");
}
},
"columns": [
{
"class": "msg_type",
"searchable": false,
"orderable": false,
"data": "DT_RowId",
"defaultContent": "",
},
{ "data": "image", "class": "img", "orderable": false },
{ "data": "name", "class": "name", "orderable": false },
{ "data": "store", "class": "store" },
{ "data": "price", "class": "price" },
{
"class": "percent",
"data": null,
"defaultContent": ""
},
{ "data": "added_date", "class": "date" },
{
"class": "a-imp btn-imp",
"orderable": false,
"data": null,
"defaultContent": ""
},
],
"createdRow": function( row, data, dataIndex ) {
console.log("here");
var msg_type = $(row).find(".msg-type").eq(0);
var price = $(row).find(".price").eq(0);
var percent = $(row).find(".percent").eq(0);
percent.html(((data.old_price - data.price)/data.old_price)*100)+"%";
},
"drawCallback" : function( settings ) {
alert( 'DataTables has redrawn the table' );
}
} );
inbox_t.on( 'draw', function () {
console.log("drwing");
} );
i handle server side using class.ssp.php:
require_once("../bootstrap/bootstrap.php");
$token = $_GET["token"];
$user = new YPAuth($token);
if(!$user->getValidate()){
echo "invalid user\n";
}
$table = "inbox_".$user->getId();
$primaryKey = 'id';
$columns = array(
array(
'db' => 'iid',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row ) {
return $d;
}
),
array( 'db' => 'name', 'dt' => 'name' ),
array( 'db' => 'link', 'dt' => 'link' ),
array(
'db' => 'image',
'dt' => 'image',
'formatter' => function( $d, $row ){
return "<img src='$d'>";
}
),
array( 'db' => 'store', 'dt' => 'store' ),
array( 'db' => 'status', 'dt' => 'status' ),
array( 'db' => 'price', 'dt' => 'price' ),
array( 'db' => 'old_price', 'dt' => 'old_price' ),
array( 'db' => 'price_table', 'dt' => 'price_table' ),
array( 'db' => 'extra_table', 'dt' => 'extra_table' ),
array( 'db' => 'price_log_chart', 'dt' => 'price_log_chart' ),
array( 'db' => 'seen', 'dt' => 'seen' ),
array( 'db' => 'important', 'dt' => 'important' ),
array( 'db' => 'added_date', 'dt' => 'added_date' ),
);
$db_conf = array(
'user' => DATABASE_USERNAME,
'pass' => DATABASE_PASSWORD,
'db' => DATABASE_NAME,
'host' => DATABASE_ADDRESS
);
$where = "";
echo json_encode(
SSP::complex( $_GET, $db_conf, $table, $primaryKey, $columns, null, null )
);
the result from server is json like this:
Object {draw: 1, recordsTotal: 716, recordsFiltered: 716, data: Array[10]}
data: Array[10]
0: Object
DT_RowId: "1720_2"
added_date: "1453494600"
extra_table: "[]"
image: ""
important: "0"
link: ""
name: "test"
old_price: "0"
price: "0"
price_log_chart: "[]"
price_table: "[]"
seen: "0"
status: "0"
store: ""
__proto__: Object
1: Object
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object
length: 10
__proto__: Array[0]
draw: 1
recordsFiltered: 716
recordsTotal: 716
__proto__: Object
now in my html the only element it generate is:
<div id="dt-inbox_wrapper" class="dataTables_wrapper no-footer">
<div class="top">
<div id="dt-inbox_filter" class="dataTables_filter"><label>search: <input type="search" class="" placeholder="" aria-controls="dt-inbox"></label></div>
<div class="dataTables_length" id="dt-inbox_length">
<label>
<select name="dt-inbox_length" aria-controls="dt-inbox" class="">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</label>
</div>
<div class="dataTables_paginate paging_simple_numbers" id="dt-inbox_paginate"></div>
<div class="clear"></div>
</div>
<div id="dt-inbox_processing" class="dataTables_processing" style="display: block;">Proccessing...</div>
<table id="dt-inbox" class="table display dataTable no-footer" cellspacing="0" width="100%" style="width: 100%;" role="grid" aria-describedby="dt-inbox_info">
<thead>
<tr role="row">
<th class="msg_type sorting_disabled" rowspan="1" colspan="1" style="width: 0px;"></th>
<th class="img sorting_disabled" rowspan="1" colspan="1" style="width: 0px;"></th>
<th class="name sorting_disabled" rowspan="1" colspan="1" style="width: 41px;"></th>
<th class="store sorting" tabindex="0" aria-controls="dt-inbox" rowspan="1" colspan="1" style="width: 54px;"></th>
<th class="price sorting" tabindex="0" aria-controls="dt-inbox" rowspan="1" colspan="1" style="width: 35px;"></th>
<th class="percent sorting" tabindex="0" aria-controls="dt-inbox" rowspan="1" colspan="1" style="width: 73px;"></th>
<th class="date sorting" tabindex="0" aria-controls="dt-inbox" rowspan="1" colspan="1" style="width: 31px;"></th>
<th class="a-imp btn-imp sorting_disabled" rowspan="1" colspan="1" style="width: 0px;"></th>
</tr>
</thead>
<tbody></tbody>
</table>
<div class="bottom">
<div class="dataTables_info" id="dt-inbox_info" role="status" aria-live="polite"></div>
<div class="dataTables_paginate paging_simple_numbers"></div>
<div class="clear"></div>
</div>
</div>
and as you can see tbody is empty.
please help me... tanx
This discussion has been closed.
Answers
Found the solution guys...