I need to apply a toggle sort on a datetime column in Vuesax data table I'm using. The toggle sort works on all other columns, except for the datetime column. My code is as follows (I've only written code relevant to the question, please assume the users data is loaded correctly):
<template>
<div>
<vs-table search :data="users">
<template slot="thead">
<vs-th sort-key="name">
Full Name
</vs-th>
<vs-th sort-key="email">
Email
</vs-th>
<vs-th sort-key="last_login">
Last Logged-in
</vs-th>
</template>
<template slot-scope="{data}">
<vs-tr
:key='index'
v-for='(user, index) in data'
>
<vs-td :data="user.name">
{{user.name}}
</vs-td>
<vs-td :data="user.email">
{{user.email}}
</vs-td>
<vs-td :data="formattedDateTime(user.last_login)">
{{formattedDateTime(user.last_login)}}
</vs-td>
</vs-tr>
</template>
</vs-table>
</div>
</template>
<script>
import moment from 'moment'
export default {
methods: {
formattedDateTime(dateTime) {
return dateTime ? moment(String(dateTime)).format('DD/MM/YYYY hh:mm A') : "N/A";
}
}
}
</script>
I welcome all suggestions, but my guess is Vuesax is not being able to detect the column data type; if there was a way in which I could enforce the data type for the datetime column, that might fix the issue.