【发布时间】:2019-02-10 00:28:33
【问题描述】:
我正在使用Angular DataTables 来显示存储在数据库中的一些数据。有一列名为 description 可以包含大量文本,理想情况下它的宽度应该比其余列大:
我尝试使用columnDefs 和autoWidth,但没有成功(我单独尝试了两者,也尝试了两者的组合)。在我的component.ts 文件中:
dtOptions = {
pagingType: 'full_numbers',
pageLength: 5,
scrollX: true,
autoWidth: false,
columnDefs: [{width: '40%', targets: 5}]
};
然后在component.html中
<table datatable [dtOptions]="dtOptions" class="row-border hover" style="width:100%">
<thead>
<tr>
<th *ngFor="let column of feedbackTable.columns">
{{ column }}
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of feedbackTable.data">
<td *ngFor="let cell of row">
{{cell}}
</td>
</tr>
</tbody>
</table>
scrollX 工作正常,但是,我没有更改列宽。我是否正确使用了dtOptions?
当我合并下面的答案时,它仍然不会影响列的宽度:
<th *ngFor="let column of feedbackTable.columns" [class.description]="column === 'user_description'">
和
th.description {
width: 40% !important;
}
还是给
【问题讨论】:
-
Angular 数据表似乎没有通过
dtOptions设置列宽的选项,但您可以使用 CSS 实现此目的 -
@mkhayata:你能详细说明一下吗?你会在
ngFor部分添加这个吗? -
我已经发布了答案
-
@davidkonrad 感谢您的链接!目前正在旅行,所以我只能在几天内测试它。
标签: angular datatables datatables-1.10 angular-datatables