-
Notifications
You must be signed in to change notification settings - Fork 61
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Row selection via checkbox (FR: provide slot for this) #69
Comments
This is already possible, the Now, honestly, once you add your own checkboxes it is better to handle the selected state outside of the plugin. So you can keep track of what is selected outside of the table plugin. Please let me know if you need help implementing it. |
@tochoromero thanks for your message! Do you suggest something like this for the vue3 version? <VTable
ref="usersTable"
:data="users"
selectionMode="multiple"
selectedClass="selected-row"
@stateChanged="selectedRows = $event.selectedRows"
>
<template #head>
<th>
<input
type="checkbox"
:value="selectedRows.length === users.length"
@input="() => selectedRows.length === users.length ? $refs.usersTable.deselectAll() : $refs.usersTable.selectAll()"
/>
Select all
</th>
<th>Name</th>
</template>
<template #body="{ rows }">
<VTr
v-for="row in rows"
:key="row.guid"
:row="row"
>
<td>
<input
type="checkbox"
:value="selectedRows.find(_row => _row.id === row.id)"
@input="() => selectedRows.find(_row => _row.id === row.id) ? $refs.usersTable.deselectRow(row) : $refs.usersTable.selectRow(row)"
/>
</td>
<td>{{ row.name }}</td>
</VTr>
</template>
</VTable> My Questions
EDIT: I believe my note on An alternate approachI'm still learning about the Vue 3 syntax changes, but having used Vue ever since version one, I learned over the years that's it's way better to provide functionality to slot content via the Take your <template>
<tr>
<slot :rowIsSelected="rowIsSelected" />
</tr>
</template>
<script>
export default {
name: 'VTr',
data () {
return { rowIsSelectedInner: false }
},
computed: {
rowIsSelected: {
get() {
return this.rowIsSelectedInner
},
set() {
// whatever logic you need to do
},
},
},
}
</script> Then you can make it (a) very easy for the user to programatically select or deselect a row, and (b) I feel it's cleaner and slightly safer than working with refs. (but that's more of a personal opinion) The way the user could now select a single row, or even all rows would be: <VTable>
<VTh>
<template v-slot="scope">
<td>
<input
type="checkbox"
v-model="scope.allRowsSelected"
/>
</td>
<td>{{ row.name }}</td>
</template>
</VTh>
<VTr
v-for="row in rows"
:key="row.guid"
:row="row"
>
<template v-slot="scope">
<td>
<input
type="checkbox"
v-model="scope.rowIsSelected"
/>
</td>
<td>{{ row.name }}</td>
</template>
</VTr>
</VTable> If you understand what I mean? :O
EDIT: I've made a PR related to this down below. |
For question 3 above, see this PR: |
Hey @tochoromero Here is an early PR with a slight change supporting my philosophy about using I would love to expand this PR to pass more focussed scope via the |
Hey @mesqueeb I just published a new version with new support slots for row selection. Please take a look: https://vue-smart-table.netlify.app/selection.html#advanced-selection |
@tochoromero oh? Did you see my PR here? |
@tochoromero I made a final post on that old PR of mine! Would love it if you could have a look :) |
I strongly believe that customisation of the table features that involves UI is best done by providing a slot for the developer!
For row selection: currently you allow selection of the row itself with customisation via a CSS class.
My requirement:
I'm imagining the slot syntax could look something like this:
What do you think?
The text was updated successfully, but these errors were encountered: