代码之家  ›  专栏  ›  技术社区  ›  CodeChanger

如何在primeng中的冻结列和未冻结列表中设置不同的列样式和宽度

  •  1
  • CodeChanger  · 技术社区  · 7 年前

    我目前正在使用带有冻结列功能的priming表控件。

    一切正常,我可以得到冻结列,但现在我想修改我的冻结和未冻结列样式和自定义列宽度,我已经使用下面的属性。

    代码:

    <p-table [columns]="scrollableCols" [frozenColumns]="frozenCols" [value]="cars" [scrollable]="true" scrollHeight="300px" frozenWidth="250px">
      <ng-template pTemplate="colgroup" let-columns>
        <colgroup>
          <col style="width:200px"> 
          <col style="width:50px">
          <col style="width:100px">
          <col style="width:100px"> 
          <col style="width:100px">
          <col style="width:100px">
        </colgroup>
      </ng-template>
      <ng-template pTemplate="header" let-columns>
        <tr>
          <th *ngFor="let col of columns">
            {{col.header}}
          </th>
        </tr>
      </ng-template>
      <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr>
          <td *ngFor="let col of columns">
            {{rowData[col.field]}}
          </td>
        </tr>
      </ng-template>
    </p-table>
    

    enter image description here

    是否可以添加不同尺寸的冷冻&解冻柱子?

    1 回复  |  直到 5 年前
        1
  •  2
  •   phucnh    7 年前

    你所需要的只是 pTemplate="frozencolgroup"

    <ng-template pTemplate="frozencolgroup" let-columns>
            <colgroup>
                <col style="width:200px">
                <col style="width:50px">
            </colgroup>
        </ng-template>
        <ng-template pTemplate="colgroup" let-columns>
            <colgroup>
                <col style="width:100px">
                <col style="width:100px">
                <col style="width:100px">
                <col style="width:100px">
            </colgroup>
        </ng-template>
    

    here

    更新: 使用滚动表可以断开行高。下面是修复此问题的提示函数

    makeRowsSameHeight() {
        setTimeout(() => {
          if ($('.ui-table-scrollable-wrapper').length) {
            let wrapper = $('.ui-table-scrollable-wrapper');
            wrapper.each(function () {
              let w = $(this);
              let frozen_rows: any = w.find('.ui-table-frozen-view tr');
              let unfrozen_rows = w.find('.ui-table-unfrozen-view tr');
              for (let i = 0; i < frozen_rows.length; i++) {
                if (frozen_rows.eq(i).height() > unfrozen_rows.eq(i).height()) {
                  unfrozen_rows.eq(i).height(frozen_rows.eq(i).height());
                } else if (frozen_rows.eq(i).height() < unfrozen_rows.eq(i).height()) {
                  frozen_rows.eq(i).height(unfrozen_rows.eq(i).height());
                }
              }
            });
          }
        });
      }
    

    更新演示: https://stackblitz.com/edit/angular-primeng-table-frozen-columns-dpsm8l