Datatables Server Side Problema
Olá companheiros, estou desenvolvendo uma listagem de noticias com Datatables Server-side devido a aglomeração de dados futuros e estou com um pequeno problema.
O problema é quando irei acrescentar os dados para as colunas no $nestedData, onde irá imprimir todos os dados somente funciona até a segunda coluna. Ocorrendo o erro: DataTables warning: table id=server-side - Requested unknown parameter '2' for row 0, column 2. For more information about this error, please see http://datatables.net/tn/4
Caso eu adicione para imprimir a terceira coluna, dá erro! A Datatabless para. Conforme foto.
/applications/core/interface/imageproxy/imageproxy.php?img=https://i.stack.imgur.com/4eQqR.png&key=42d6b2f92b3bc73eedd35651cffc83436fb3b2d5de7a5fae5d55a88166cf020a" />
JS Datatables
<script>
$(document).ready(function(e){
$('#server-side').dataTable({
"bProcessing": true,
"serverSide": true,
language: {
processing: "Processando...",
},
"ajax":{
url :"server-side/nov.php",
type: "POST",
},
"order": [ 0, "desc"],
});
table.destroy();
table = $('#server-side').DataTable( {
searching: false
} );
});
Código PHP
<?php
require_once '../database/mysql.php';
$db = new Mysql;
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
$columns = array(
0 => 'noticia_id',
1 => 'noticia_foto',
2 => 'noticia_title',
3 => 'noticia_category',
4 => 'noticia_data',
5 => 'noticia_autor'
);
$where_condition = $sqlTot = $sqlRec = "";
if( !empty($params['search']['value']) ) {
$where_condition .= " WHERE ";
$where_condition .= " ( noticia_title LIKE '%".$params['search']['value']."%' ";
$where_condition .= " OR noticia_content LIKE '%".$params['search']['value']."%' )";
}
$sql_query = "SELECT noticia_id, noticia_foto, noticia_title, noticia_category, noticia_data, noticia_autor FROM noticia ";
$sqlTot .= $sql_query;
$sqlRec .= $sql_query;
if(isset($where_condition) && $where_condition != '') {
$sqlTot .= $where_condition;
$sqlRec .= $where_condition;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$db->query( $sqlTot )->fetchAll();
$totalRecords = $db->rows;
$db->query( $sqlRec )->fetchAll();
if ($db->rows >= 1):
$querys = $db->data;
foreach ($querys as $query):
$q = (object) $query;
if ( $q->noticia_foto == "" || strlen( $q->noticia_foto ) <= 1 )
{
$foto = "../images/sem-foto.jpg";
}
else
{
$foto = "../thumb.php?img=uploads/noticias/$q->noticia_foto";
}
$queryRecords = $db->rows;
$nestedData = array();
$nestedData[] = $q->noticia_id;
$nestedData[] = "<img src=\"$foto\" style=\"width:40px; height:30px;\" />";
// SÓ IMPRIMI ATÉ AQUI
//$nestedData[] = $q->noticia_title;
//$nestedData[] = $q->noticia_category;
//$nestedData[] = $q->noticia_data;
//$nestedData[] = $q->noticia_autor;
//$nestedData[] = "Ações";
$data[] = $nestedData;
endforeach;
endif;
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval( $totalRecords ),
"data" => $data
);
echo json_encode($json_data);
?>
Alguém pode me ajudar? já tentei de todas as formas possíveis mais o erro persiste!Discussão (0)
Carregando comentários...