【发布时间】:2020-01-29 17:26:39
【问题描述】:
我正在尝试使用属性“数据”在表格中显示我的数据,但表格不起作用。我使用本地字符串数组进行了测试并且效果很好,我不知道为什么使用对象时表格不起作用
ngAfterViewInit() {
this.listarNotificacao()
$('#datatables').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
lengthChange: false,
responsive: true,
searching: true,
data: this.notificacoes,
columns: [{
data: 'guidNotificacao'
},
{
data: 'titulo'
},
{
data: 'descricao'
},
{
data: 'escopo'
},
],
language: {
search: "_INPUT_",
searchPlaceholder: "Pesquisar promoções",
},
}
});
const table = $('#datatables').DataTable();
$('#inputSearch').on('keyup', function() {
table.search(this.value).draw();
});
}
<div class="material-datatables">
<table id="datatables" class="table table-no-bordered " cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>#</th>
<th>Título</th>
<th>Descrição</th>
<th>Escopo</th>
</tr>
</thead>
</table>
</div>
【问题讨论】:
-
在我看来你有一个额外的
} -
const table = $('#datatables').DataTable();不需要在那里。分配table您之前构建的数据表对象。 -
正如@nullptr.t 所说,您正在实例化您的数据表两次。
标签: javascript angular datatable