You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular Material分页器每页条数选项显示位置异常排查

问题原因及解决方法

这个问题是因为你使用了Bootstrap的table-responsive容器包裹Angular Material表格,该容器默认添加的overflow-x: auto样式会和Angular Material分页器的布局规则冲突,导致“Items per page”的文本被挤到表格下方,而非选择框正下方。

具体解决步骤

  • 直接移除包裹<table mat-table>的table-responsive容器:Angular Material的mat-table本身已具备响应式适配能力,不需要依赖Bootstrap的这个类来实现滚动效果。
  • 若你确实需要保留水平滚动效果,可自定义容器样式替代table-responsive:
    .custom-table-scroll {
      overflow-x: auto;
      width: 100%;
    }
    
    然后将模板中的table-responsive替换为这个自定义类。

另外,需确认Angular Material的主题样式已正确引入(检查angular.json中是否包含@angular/material/prebuilt-themes/xxx.css的引用),样式加载顺序异常也可能导致这类布局问题。

修改后的核心模板代码示例:

<div class="container">
<div class="row">
    <div class="col-md-12">          
        <div>
            <h3>MyTable</h3>
            <!-- 移除原table-responsive容器,或替换为自定义样式容器 -->
            <div>
                <table mat-table [dataSource]="dataSource" class="mat-elevation-z8" width="100%">
                    <!-- 表格列定义部分保持不变 -->
                    <ng-container matColumnDef="index">
                        <th mat-header-cell *matHeaderCellDef> x </th>
                        <td mat-cell *matCellDef="let element; let i = index;">{{ (i+1) + (paginator.pageIndex * paginator.pageSize)}}</td>
                    </ng-container>
        
                    <ng-container matColumnDef="x1">
                        <th mat-header-cell *matHeaderCellDef> x1 </th>
                        <td mat-cell *matCellDef="let element"> {{element.x1}} </td>
                    </ng-container>
        
                    <ng-container matColumnDef="x2">
                        <th mat-header-cell *matHeaderCellDef> x2</th>
                        <td mat-cell *matCellDef="let element"> {{element.x2}} </td>
                    </ng-container>
        
                    ....
                    ....
                    ....
        
                    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
                    <tr mat-row 
                        *matRowDef="let reading; columns: displayedColumns;"
                        (click) = "onRowClicked(reading)"
                    ></tr>
                </table>
            </div>
        
            <mat-paginator #paginator
                [length]="countX"
                [pageSize]="pageSize"
                [pageSizeOptions]="pageSizeOptions"
                aria-label="Choose page"
                showFirstLastButtons>
            </mat-paginator>
        </div>
    </div>
</div>
</div>

内容的提问来源于stack exchange,提问作者Hrvoje T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 13:41:25