0

代码链接为:https ://plnkr.co/edit/V9ZkLzDeVo15ngIu2Glo?p=preview

我的模板是:

<p-dataTable [value]="cars">
<p-headerColumnGroup>
    <p-row>
        <p-column header="Vin" rowspan="2" [sortable]="true"></p-column>
        <p-column header="Info" colspan="3"></p-column>
    </p-row>
    <p-row>
        <p-column header="Year" [sortable]="true"></p-column>
        <p-column header="Brand" [sortable]="true"></p-column>
        <p-column header="Color" [sortable]="true"></p-column>
    </p-row>
</p-headerColumnGroup>
<p-column field="vin"></p-column>
<p-column field="year"></p-column>
<p-column field="brand"></p-column>
<p-column field="color"></p-column>

当有 colgroup 标头时,排序功能将不起作用。有人可以建议我吗?

4

1 回答 1

2

那是因为p-dataTable找不到标题和列之间的连接。添加sortField到标题将有助于建立它们:

<p-headerColumnGroup>
    <p-row>
        <p-column header="Vin" sortField="vin" rowspan="2" [sortable]="true"></p-column>
        <p-column header="Info" colspan="3"></p-column>
    </p-row>
    <p-row>
        <p-column header="Year" sortField="year" [sortable]="true"></p-column>
        <p-column header="Brand" sortField="brand" [sortable]="true"></p-column>
        <p-column header="Color" sortField="color" [sortable]="true"></p-column>
    </p-row>
</p-headerColumnGroup>
于 2017-08-21T03:11:08.773 回答