Tem suporte integrado para lidar com grandes conjuntos de dados.
Para habilitar o carregamento lento, precisa ser implementado na consultar a fonte de dados, quando ocorre paginação, classificação, filtragem ou rolagem.
O carregamento deve ser executado na consulta construída usando as informações passadas para o método de carregamento ajax.
$render=explode(" ",$_POST["partial_render"]);
$ordem="nome";
$direcao="ASC";
if($_POST["tabela_sortKey"]=="nome"){
$ordem = "nome";
}
if($_POST["tabela_sortKey"]=="pais"){
$ordem = "p.pais";
}
if($_POST["tabela_sortKey"]=="representante"){
$ordem = "r.representante";
}
if($_POST["tabela_sortKey"]=="companhia"){
$ordem = "o.companhia";
}
$f_nome = $_POST["nome:filter"];
$f_pais = $_POST["pais:filter"];
$f_representante = $_POST["representante:filter"];
$f_companhia = $_POST["companhia:filter"];
if(isset($_POST["tabela_first"])){
$_SESSION["inicio"]=$_POST["tabela_first"];
}else{
$_SESSION["inicio"]="10";
}
$limit= "";
if(isset($_POST["tabela_rows"])){
$_SESSION["fim"]=$_POST["tabela_rows"];
$limit=" LIMIT ".$_SESSION["inicio"].",".$_SESSION["fim"];
}else{
$_SESSION["fim"]="10";
}
if($_POST["tabela_sortDir"]=="1"){
$direcao="ASC";
}
if($_POST["tabela_sortDir"]=="-1"){
$direcao="DESC";
}
$query = "SELECT * FROM clientes c INNER JOIN paises p ON c.pais = p.id_pais INNER JOIN representante r ON c.representante=r.id_representante INNER JOIN companhias o ON c.companhia=o.id_companhia WHERE nome LIKE "".$f_nome."%" AND p.pais LIKE "".$f_pais."%" AND r.representante LIKE "".$f_representante."%" AND c.companhia LIKE "".$f_companhia."%" ORDER BY ".$ordem." ".$direcao." ".$limit;
$rslt = $pdo->query($query);
$total_rgtr = $rslt->rowCount();
$query.=" ".$limit;
$result = $pdo->query($query);
$resposta="";
while ($linha = $result->fetch(PDO::FETCH_ASSOC)) {
$resposta.="
<tr data-ri="".$linha["id_cliente"]."" data-rk="".$linha["id_cliente"]."" class="ui-widget-content ui-datatable-even ui-datatable-selectable" role="row" aria-selected="false">
<td role="gridcell" class="">".$linha["nome"]."</td>
<td role="gridcell" class="">
<span class="flag flag-".$linha["sigla"]."" style="width: 30px; height: 20px"></span><span style="vertical-align: middle; margin-left: .5rem">".$linha["pais"]."</span>
</td>
<td role="gridcell" class="">".$linha["companhia"]."</td>
<td role="gridcell" class=""><img src="/sistema/resource/images/avatar/".$linha["foto_representante"].".png" alt="" width="32" style="vertical-align: middle" /><span style="vertical-align: middle; margin-left: .5rem">".$linha["representante"]."</span></td>
</tr>
";
}
$extension="{"totalRecords":".$total_rgtr."}";
if($render[0]=="customerDetail"){
$query = "SELECT * FROM clientes c INNER JOIN paises p ON c.pais = p.id_pais INNER JOIN representante r ON c.representante=r.id_representante INNER JOIN companhias o ON c.companhia=o.id_companhia WHERE id_cliente="".$_POST["tabela_selection"].""";
$result = $pdo->query($query);
$linha = $result->fetch(PDO::FETCH_ASSOC);
$resposta="
<div id="customerDetail" class="ui-outputpanel ui-widget" style="text-align:center;">
<table class="ui-panelgrid ui-widget" role="grid">
<tbody>
<tr class="ui-widget-content">
<td role="gridcell" class="ui-panelgrid-cell label">Nome:</td>
<td role="gridcell" class="ui-panelgrid-cell value">".$linha["nome"]."</td>
</tr>
<tr class="ui-widget-content">
<td role="gridcell" class="ui-panelgrid-cell label">País</td>
<td role="gridcell" class="ui-panelgrid-cell value">
<span class="flag flag-".$linha["sigla"]."" style="width: 30px; height: 20px"></span>
<span style="vertical-align: middle; margin-left: .5rem">".$linha["pais"]."</span>
</td>
</tr>
<tr class="ui-widget-content">
<td role="gridcell" class="ui-panelgrid-cell label">Companhia:</td>
<td role="gridcell" class="ui-panelgrid-cell value">".$linha["companhia"]."</td>
</tr>
<tr class="ui-widget-content">
<td role="gridcell" class="ui-panelgrid-cell label">Representante:</td>
<td role="gridcell" class="ui-panelgrid-cell value">
<img src="/sistema/resource/images/avatar/".$linha["foto_representante"].".png" alt="" width="32" ismap="false" style="vertical-align: middle" />
<span style="vertical-align: middle; margin-left: .5rem">".$linha["representante"]."</span>
</td>
</tr>
</tbody>
</table>
</div>
";
}
dc.cw("DataTable", "widget_tabela", {
id: "tabela"
, paginator: {
id: ["tabela_paginator_top", "tabela_paginator_bottom"]
, rows: 10
, rowCount:
, page: 0
, currentPageTemplate: "({currentPage} de {totalPages})"
}
, selectionMode: "single"
, filter: true
, sorting: true
, multiSort: true
, sortMetaOrder: [""]
, groupColumnIndexes: []
, disableContextMenuIfEmpty: false
, behaviors: {
rowSelect: function (ext, event) {
dc.ab({
s: "tabela"
, e: "rowSelect"
, f: "formulario"
, p: "tabela"
, u: "customerDetail"
, onco: function (xhr, status, args, data) {
DC("customerDialog").show();
}
}, ext);
}
}
});
dc.cw("Dialog", "customerDialog", {
id: "detalhes"
, resizable: false
, modal: true
, showEffect: "fade"
, hideEffect: "fade"
});