angular - 如何使用 antd for angular 将表格中的分页位置更改为居中?
问题描述
我在 Antd vs.12.0.2 上,我尝试使用 Angular 和 Antd for Angular 实现数据表。
这是我的 nz-table 代码内容。
<nz-table
#membersTable
nz-show-pagination
nzSize="default"
nzTableLayout="fixed"
nzPaginationType="default"
nzPaginationPosition="bottom"
[nzData]="members"
>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone number</th>
<th>Accounts</th>
<th nzWidth="70px"></th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let member of membersTable.data">
<tr class="org-admin-member-row" [member]="member"></tr>
</ng-container>
</tbody>
</nz-table>
没有属性可以将分页移到表格的中心。所以,我试图覆盖样式,但没有任何改变。
这是我在较少文件中尝试的内容。
nz-table {
nz-pagination {
justify-content: center;
}
}
不能覆盖antd类样式吗?
解决方案
哦,我找到了解决这个问题的答案。为了帮助其他与我遇到同样问题的人,我将向公众发布这个答案。
Angular 为其样式添加前缀,这些样式通过其组件 ID 用于组件,如下所示。
.header[_ngcontent-jjj-c93] .user-dropdown[_ngcontent-jjj-c93] {
cursor: pointer;
}
.content[_ngcontent-jjj-c93] {
background-color: white;
}
.bottom-menu[_ngcontent-jjj-c93] {
position: absolute;
bottom: 0;
}
因此,当我尝试覆盖样式时,它们的前缀是这样的。
nz-table[_ngcontent-jjj-c198] nz-pagination[_ngcontent-jjj-c198] {
justify-content: center;
}
这就是为什么覆盖样式不能改变分页位置的原因,所以我在 custom.less 文件中创建了覆盖样式,该文件位于 src/app/styles 文件夹中,用于在应用程序中定义自定义全局样式。
代码如下所示。
org-admin-members {
.ant-table-pagination {
justify-content: center !important;
}
}
它成功地改变了分页位置。
注意:您必须确保在 src/app/styles.less 文件中包含 custom.less 文件,并且应该将 '!important' 规则添加到 css 样式中。
推荐阅读
- spring-boot - 无法让此控制器返回具有正确 mime 类型的文件
- reactjs - 将异步函数放入 useEffect 后出现错误
- javascript - 通过来自 woocommerce HTML 变体的数据集生成 JS 变量数组
- c# - Windows SC.exe如何查询服务的控制码
- visual-studio-code - indentationRule 在 vscode language-configuration.json 中不起作用
- c# - aws cdk 应用程序负载均衡器无法创建错误,缺少默认操作所需的参数
- python - 用 pandas 清理这些数据
- javascript - Electron auto updater setup with own server (generic provider)
- javascript - 为什么我的嵌入改变了我的页面样式
- python - 如何在同一视图中指定不同应用程序的模型但名称相同