Skip to content

Commit 112466c

Browse files
committed
docs: provide usage instructions on Selectable Cell
1 parent 52076a7 commit 112466c

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Custom Cell Component](#custom-cell-component)
1717
* [Action Buttons](#action-buttons)
1818
* [Editable cells](#editable-cells)
19+
* [Selectable rows](#selectable-rows)
1920
* [Text](#text)
2021
* [Adding Language](#adding-language)
2122
* [Layout](#layout)
@@ -536,6 +537,59 @@ export default {
536537
</script>
537538
```
538539

540+
#### Selectable rows
541+
542+
`VueDataTable` provides the built-in `vdt-cell-selectable` component to select
543+
table rows.
544+
545+
```javascript
546+
const props = {
547+
columns = [
548+
{
549+
title: "",
550+
component: "vdt-cell-selectable" // <-- ADD THIS
551+
},
552+
{ key: "name" },
553+
{ key: "email" },
554+
/* ... */
555+
],
556+
vKey = "id",
557+
};
558+
const data = [
559+
{ id: 1, name: "joe", email: "joe@example.com" },
560+
/* ... */
561+
]
562+
```
563+
564+
When the user toggles the checkbox, `VueDataTable` emits an event called
565+
`userEvent` with the following payload:
566+
567+
```javascript
568+
{
569+
action: "select",
570+
selected: true || false, // this is the current value of the checkbox
571+
data: {}, // this is the current row (example, a user from an users array)
572+
}
573+
```
574+
575+
You can have a reactive variable to keep track of selected items:
576+
577+
```javascript
578+
const selected = ref([]);
579+
580+
const handleSelect(payload) {
581+
const item = payload.data;
582+
if (payload.selected) {
583+
selected.value.push(item);
584+
} else {
585+
selected.value = selected.value.filter((x) => x.id !== item.id);
586+
}
587+
}
588+
```
589+
590+
You can use this variable to perform bulk operations, such as mass deletion or
591+
mass edition.
592+
539593
### Text
540594

541595
Currently, `VueDataTable` has support for the following languages: English (en),

0 commit comments

Comments
 (0)