0

I have the below datatable with a strange behavioir:

<DataTable
    :scrollable="true"
    :value="shipments"
    :totalRecords="shipments.length"
    :reorderableColumns="true"
    :alwaysShowPaginator="false"
    :paginator="true"
    :rows="10"
    :resizableColumns="true"
    columnResizeMode="fit"
    sortMode="multiple"
    :stripedRows="true"
    removableSort
    dataKey="reference"
    responsiveLayout="scroll">
    <template #empty> No records found </template>
    <Column field="reference" header="Shipment Number" :sortable="true" frozen />
    <Column header="Shipper" style="text-transform: capitalize">
        <template #body="slotProps">
            {{ slotProps.data.shipper.name.toLocaleLowerCase() }}
        </template>
    </Column>
</DataTable>

If I try to reorder (dragging) the columns, I get the below error. Every time I try to reorder, the reference column is added to the table.

[Vue warn]: Duplicate keys found during update: "reference" Make sure keys are unique.

If I remove this part of the Shipper column:

<template #body="slotProps">
     {{ slotProps.data.shipper.name.toLocaleLowerCase() }}
</template>

And just reference the shipper name using field="shipper.name" it works fine without any errors.

What am I doing wrong?

1 Answer 1

1

Reading through the documentation I can see that I missed an important part when using the reorderColumns functionality.

I need to set a columnKey if the specific column doesn't have a field defined as per the docs:

If the column has no field, use columnKey instead as it is mandatory for columns to have unique keys when reordering is enabled.

I added this, and it works now:

<Column header="Shipper" columnKey="shipper" style="text-transform: capitalize">
    <template #body="slotProps">
        {{ slotProps.data.shipper.name.toLocaleLowerCase() }}
    </template>
</Column>
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.