Angular PrimeNG DataTable排序

时间:2017-08-21 02:32:41

标签: angular primeng primeng-datatable

代码链接为: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标头时,sort函数将不起作用。有人可以就此提出建议吗?

1 个答案:

答案 0 :(得分: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>