【发布时间】:2020-09-09 17:25:05
【问题描述】:
我正在构建一个周费用报告组件。报告应该是响应式的,所以我在正文中有详细信息,在页脚中有列总计。
我在 Angular 10 应用程序中使用 PrimeNG 库。这是一个 PrimeNG CSS 问题。费用报告通常显示页眉、正文和页脚。当费用报告响应时,它只显示正文。这似乎是 Primefaces 根据以下 table.css 文件设计的:
@media screen and (max-width: 40em) {
.p-datatable.p-datatable-responsive .p-datatable-thead > tr > th,
.p-datatable.p-datatable-responsive .p-datatable-tfoot > tr > td {
display: none !important;
}
...
我正在尝试显示页脚,但没有成功。当我查看 Chrome 开发者工具时,我看到上面的 table.css 覆盖了我在以下应用程序 style.css 文件中的 CSS:
@media screen and (max-width: 40em) {
.p-datatable.p-datatable-responsive .p-datatable-tfoot > tr > td {
text-align: left;
display: block;
width: 100%;
float: left;
clear: left;
border: 0 none;
}
.p-datatable.p-datatable-responsive .p-datatable-tfoot > tr > td .p-column-title {
padding: .4rem;
min-width: 30%;
display: inline-block;
margin: -.4em 1em -.4em -.4rem;
font-weight: bold;
}
}
我基本上从 table.css 中获取了上面的 CSS,并将其更改为 tfoot 而不是 tbody。我在 table.css 中的 CSS 下方的 Chrome 开发人员工具中看到了上面的 CSS,但是 display: block; 行有一个删除线。
我的 CSS 在 angular.json 文件中设置如下:
angular.json
"build": {
...,
"styles": [
"node_modules/bootstrap/dist/css/bootstrap-grid.min.css",
"node_modules/primeng/resources/themes/nova/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"node_modules/primeicons/primeicons.css",
"src/styles.css"
],
以下是演示问题的示例组件。
<p-table id='weekTotals-grid' [value]='items' dataKey='ExpenseTypeId' [responsive]='true'>
<ng-template pTemplate='header'>
<tr>
<th style='width: 170px;'></th>
<th><div style='width: 100px;'>Total</div></th>
</tr>
</ng-template>
<ng-template pTemplate='body' let-rowData>
<tr>
<td>
<span class='p-column-title'>Expense Type</span>
{{ rowData['ExpenseType'] }}
</td>
<td>
<span class='p-column-title'>Total</span>
<div style='width: 80px;' class='nsg-wet-numeric'>
{{ rowData['ExpenseTotal'] }}
</div>
</td>
</tr>
</ng-template>
<ng-template pTemplate='footer' style='border-top: 1px solid black;'>
<tr>
<td>Totals</td>
<td>
<span class='p-column-title'>Grand Total</span>
{{ grandTotal }}
</td>
</tr>
</ng-template>
</p-table>
打字稿代码:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
items: any[];
grandTotal: number;
ngOnInit() {
this.items = [
{ExpenseTypeId: 1, ExpenseType: 'Gas', ExpenseTotal: 20.0},
{ExpenseTypeId: 2, ExpenseType: 'Food', ExpenseTotal: 12.88},
{ExpenseTypeId: 3, ExpenseType: 'Mileage', ExpenseTotal: 5.50}
];
this.grandTotal = 38.38;
}
}
谢谢
【问题讨论】:
标签: css angular datatables primeng