|
16 | 16 | * [Custom Cell Component](#custom-cell-component) |
17 | 17 | * [Action Buttons](#action-buttons) |
18 | 18 | * [Editable cells](#editable-cells) |
| 19 | + * [Selectable rows](#selectable-rows) |
19 | 20 | * [Text](#text) |
20 | 21 | * [Adding Language](#adding-language) |
21 | 22 | * [Layout](#layout) |
@@ -536,6 +537,59 @@ export default { |
536 | 537 | </script> |
537 | 538 | ``` |
538 | 539 |
|
| 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 | + |
539 | 593 | ### Text |
540 | 594 |
|
541 | 595 | Currently, `VueDataTable` has support for the following languages: English (en), |
|
0 commit comments