Skip to content

Commit b52b47e

Browse files
committed
Add docs
1 parent e73ad11 commit b52b47e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1913
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
/psalm.xml export-ignore
1313
/psalm.xml.dist export-ignore
1414
/testbench.yaml export-ignore
15+
/docs export-ignore

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
build
66
composer.lock
77
coverage
8-
docs
98
phpunit.xml
109
psalm.xml
1110
testbench.yaml

docs/_index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: v2
3+
slogan: A dynamic table component for Laravel Livewire.
4+
githubUrl: https://github.com/rappasoft/laravel-livewire-tables
5+
branch: master
6+
---

docs/bulk-actions/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Bulk Actions
3+
weight: 6
4+
---
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Creating bulk actions
3+
weight: 2
4+
---
5+
6+
To create bulk actions, you must specify a `method` and a `button title` in the `$bulkActions` component property.
7+
8+
```php
9+
public array $bulkActions = [
10+
'exportSelected' => 'Export',
11+
];
12+
```
13+
14+
------
15+
16+
**The following method is only available in v1.16 and above**
17+
18+
As of v1.16 you can define bulk action with a method, so you can perform other actions to determine what your actions are or perform translations on the strings:
19+
20+
```php
21+
public function bulkActions(): array
22+
{
23+
// Figure out what actions the admin gets
24+
...
25+
26+
return [
27+
'activate' => __('Activate'),
28+
'deactivate' => __('Deactivate'),
29+
];
30+
}
31+
```
32+
33+
------
34+
35+
The **key** is the Livewire method to call, and the value is the name of the item in the bulk actions dropdown.
36+
37+
You can define your method to do whatever you want:
38+
39+
```php
40+
public function exportSelected()
41+
{
42+
// Do something with the selected rows.
43+
}
44+
```
45+
46+
See [Getting the selected rows query](./getting-the-selected-rows-query) or [Getting the selected keys](./getting-the-selected-keys) to understand how to work with the selected data.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Selected keys
3+
weight: 4
4+
---
5+
6+
If you would like access to just the selected primary keys in your bulk action method, you may use the `selectedKeys` property which return an array of the selected primary keys:
7+
8+
```php
9+
public function exportSelected()
10+
{
11+
if (count($this->selectedKeys)) {
12+
// Do something with the selected rows
13+
dd($this->selectedKeys);
14+
15+
// => [
16+
// 1,
17+
// 2,
18+
// 3,
19+
// 4,
20+
// ]
21+
}
22+
23+
// Notify there is nothing to export
24+
}
25+
```
26+
27+
**Note:** See [The primary key](../usage/the-primary-key) about where this value comes from.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Selected rows query
3+
weight: 3
4+
---
5+
6+
In the component, you have access to `$this->selectedRowsQuery` which is a Builder instance of the selected rows.
7+
8+
```php
9+
public function exportSelected()
10+
{
11+
if ($this->selectedRowsQuery->count() > 0) {
12+
// Do something with the selected rows
13+
}
14+
15+
// Notify there is nothing to export
16+
}
17+
```
18+
19+
See also [Getting the selected keys](../bulk-actions/getting-the-selected-keys) if you would just like access to the selected primary keys.

docs/bulk-actions/introduction.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Introduction
3+
weight: 1
4+
---
5+
6+
Bulk actions are a way for you to perform methods on selected rows, a full-page, or all rows, at the same time.
7+
8+
By default, bulk actions are hidden. I.e. the bulk action selector, and the left-hand checkboxes do not appear until you specify at least one bulk action.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Resetting after bulk actions
3+
weight: 5
4+
---
5+
6+
If your bulk action is changing the outcome of your table, i.e. you are deleting rows or changing criteria that would alter the row set with the search criteria you have, then you may have unexpected results after the bulk action runs.
7+
8+
There is no one good way to handle this, so there are a few options available to you:
9+
10+
## 1. Reset all the filters and criteria.
11+
12+
You can reset all the filters, search, page, sorts, etc. With this method, that will essentially reload the table to what it was on the first page load with your bulk changes since the query will re-run:
13+
14+
```php
15+
public function deleteSelected()
16+
{
17+
// Delete the rows
18+
19+
$this->resetAll();
20+
}
21+
```
22+
23+
## 2. Reset specific criteria
24+
25+
You may at the end of your bulk action method reset specific parts of the UI with any of the following methods:
26+
27+
```php
28+
public function myBulkAction()
29+
{
30+
// Do something with the rows
31+
32+
// Use any of these to reset the UI to a point that makes sense after your bulk action is run:
33+
$this->resetFilters(); // Remove all the filters
34+
$this->resetSearch(); // Remove the search query
35+
$this->resetSorts(); // Remove the sorts
36+
$this->resetBulk(); // Clear the selected rows
37+
$this->resetPage(); // Go back to page 1
38+
}
39+
```

docs/columns/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Columns
3+
weight: 3
4+
---

0 commit comments

Comments
 (0)