这是我的Jquery Server Side DataTable的设置,可以正确地从数据库中返回数据,并且过滤确实可以正常工作,但是问题是每一列的选择框仅显示第一页数据中的值。
我为此使用mysql数据库
Phalcon PHP控制器操作:
public function getJsonBOMuploadAction($dummy) {
if ($this->request->isAjax()) {
$this->setJsonResponse();
$request = $this->request;
$p_draw = $request->getPost("draw");
$p_start = $request->getPost("start");
$p_length = $request->getPost("length");
$p_search = $this->GetSearchString($request->getPost("search"));
$p_col_search = $this->GetSearchString($request->getPost("columns"));
try {
$data = CallableRoutine::getDocumentRouterList($p_start
, $p_length, $p_search, intval($p_col_search[0])
, $p_col_search[1], $p_col_search[2]);
} catch (Exception $ex) {
return $ex;
}
$count = $data[count($data) - 1]["id"];
array_splice($data, count($data) - 1);
return Array("data" => $data,
"draw" => $p_draw,
"recordsFiltered" => $count,
"search" => $p_search,
"col_search" => $p_col_search,
"recordsTotal" => $count);
}
}
Jquery代码:
vm.initExampleDocrouterDatatable = function() {
$('#example_docrouter').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "./product_bom/getJsonBOMupload",
"type": "POST"
},
"columns": [
{"data": "id"},
{"data": "name"},
{"data": "description"}
],
// ==============================================================
// ====== Column filter code reference:
// ====== https://datatables.net/examples/api/multi_filter_select
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
});
};
这是我的HTML:
<table id="example_docrouter" class="table row-border hover table-responsive display nowrap table-bordered">
<thead>
<tr>
<th class="thbg thead-css">ID</th>
<th class="thbg thead-css">Name</th>
<th class="thbg thead-css">Description</th>
</tr>
</thead>
<tfoot class="noprint">
<tr>
<th class="thead-css">ID</th>
<th class="thead-css">Name</th>
<th class="thead-css">Description</th>
</tr>
</tfoot>
<tbody></tbody>
</table>
答案 0 :(得分:0)
显然,使用$ p_length进行分页。目前尚不清楚此值从何而来,您可能会发现使用Phalcon分页器很有用:https://docs.phalconphp.com/zh/3.2/db-pagination