I have a table listing my todos. In the last column, I have a button to mark the todo as finished. Because I'd like to reuse this button in other tables and views, I've added it as a component that is being imported.
Furthermore, I'd like to use a table package such as vue3-table-lite so that I can have quick and easy access to 1) filtering, 2) pagination, and 3) sorting features.
These packages typically uses :rows, which is pretty straightforward if you only have text. However, I don't know how to provide Vue components, in this case <FinishedButton /> from the last <td> shown in the last code block below.
How can I import Vue components into :rows of a table? Alternatively achieve filtering, pagination, and sorting without having to use :rows at all.
Here's how the button component is constructed:
<template>
<a v-show="todo.is_finishable" v-on:click="markFinished(todo.id)"
class="todo_finished btn btn-sm btn-light btn-light-border finalized_button">Finished</a>
</template>
<script>
export default {
name: 'FinishedButton',
props: ['todo',],
methods: {
remove: function () {
this.$emit("delete", this.todo);
},
markFinished: function (selected_todo_id) {
this.$http.patch('/api/todo/' + selected_todo_id + "/", {
status: 'Done'
})
.then(response => {
console.log(response);
this.remove();
})
.catch(e => {
console.log(e);
});
}
},
};
</script>
Here's how a simplified version of the table looks like (there's more columns in the actual table):
<table id="FOO" class="table table-hover table-sm">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr v-for="todo in todos" :key="todo.id">
<td>{{ todo.name }}</td>
<td><FinishedButton :todo=todo /></td>
</tr>
</tbody>
</table>