Page 1 of 1

DataTable sortable does not work on template column

Posted: 28 Apr 2020, 16:49
by findream
DataTable sortable works on normal column with field attribute, but does not work on template column without field attribute.
Is there any way I can choose to sort on template column as follows?

<Column :sortable="true">
<template #body="slotProps">
{{ calculateScore(slotProps.data.items) }}
</template>
</Column>

Re: DataTable sortable does not work on template column

Posted: 17 May 2020, 16:31
by cagatay.civici
It is expected, column has no idea what to use for sorting. One solution is adding a field to your row data like calculated items. Templating is useful for adding custom content but table needs metadata to use in sorting like a field.

Code: Select all

<Column :sortable="true" field="calculatedScore"></Column>

Code: Select all

rowData.calculatedScore = this.calculateScore(rowData.items)
Other alternative is custom sorting which will be in 2.0.0-final where you can implement your own sorting.