0

The code link is:https://plnkr.co/edit/V9ZkLzDeVo15ngIu2Glo?p=preview

My template is:

<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>

The sort function will not work when there is a colgroup header. Can someone please suggest me on this?

1 Answer 1

2

That's because p-dataTable could not find connections between headers and columns. Adding sortField to header will help establishing them:

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.