【发布时间】:2015-01-06 18:41:45
【问题描述】:
使用 AngularJS,我有一个 DataTable() 在服务器端模式下工作,使用 YADCF 过滤器。 现在我需要在表格之外添加一些按钮来过滤 DataTable...
来自myApp.controller的代码
var table = $('#tbl').DataTable({
stateSave: true,
stateDuration: -1,
//sRowSelect: "multi",
language: sharedProperties.getLanguageDatatable(),
dom: '<"toolbar">T<"clear">lfrtip',
"columnDefs": [
{ "data": "processosId", "targets": 0, "visible": false, "searchable": false },
{ "data": "utilizadoresId", "targets": 1, "visible": false, "searchable": false },
{ "data": "entidadesId", "targets": 2, "visible": false, "searchable": false },
{ "data": "numero", "targets": 3 },
{ "data": "nomeEntidade", "targets": 4, "visible":entidadeCol },
{ "data": "nomeUtilizador", "targets": 5, "visible":utilizadorCol },
{ "data": "estado", "targets": 6 },
],
serverSide: true,
ajax: {
"url": urlProcessos,
"error": function (reason) {
if (reason.status == 401) { // Not Authorized
self.location = '#/logout';
}
}
},
});
yadcf.init(table,
[
{ column_number: 3, filter_type: 'text', filter_default_label: "" },
{ column_number: 4, filter_type: 'text', filter_default_label: "" },
{ column_number: 5, filter_type: 'text', filter_default_label: "" },
{ column_number: 6, filter_type: 'text', filter_default_label: "", },
]);
$scope.newProcess = function () {
table.columns(6).search('Novo').draw();
}
$scope.openProcess = function () {
table.columns(6).search('Aberto').draw();
}
html页面的代码:
<a href="#" >
<div class="col-sm-3" ng-click="newProcess()">
<div class="xe-label">
<strong class="num">{{contagens.novos}}</strong>
<span>Novos Processos</span>
</div>
</div>
</a>
<a href="#" >
<div class="col-sm-3" ng-click="openProcess()">
<div class="xe-label">
<strong class="num">{{contagens.abertos}}</strong>
<span>Processos Abertos</span>
</div>
</div>
</a>
<table class="table table-striped table-bordered table-hover" id="tbl" width="100%" style="width: 100%;">
<thead>
<tr class="replace-inputs">
<th>Id</th>
//and so on...
</tr>
</thead>
<tbody></tbody>
</table>
当我单击 NewProcess 的按钮时,调用 newProcess() 函数,使用正确的过滤器向服务器发出请求,但在没有过滤器的情况下立即发出另一个请求...
如 Fiddler 所示:
【问题讨论】:
标签: angularjs jquery-datatables yadcf