Skip to content

Commit b299504

Browse files
Update readme (#13)
1 parent f8af259 commit b299504

File tree

1 file changed

+55
-100
lines changed

1 file changed

+55
-100
lines changed

README.md

Lines changed: 55 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
# Ginkelsoft DataTables
22

3-
Ginkelsoft DataTables is a flexible and easy-to-use package for managing tabular data in Laravel projects. It supports both a **base DataTable** class for traditional server-rendered apps and an **optional Livewire** component for dynamic, AJAX-driven experiences. You can easily add filtering, searching, sorting, and bulk actions with minimal setup.
3+
Ginkelsoft DataTables is a flexible and easy-to-use package for managing tabular data in Laravel projects. This package **requires Livewire** for dynamic, AJAX-driven experiences. You can easily add filtering, searching, sorting, and bulk actions with minimal setup.
44

55
---
66

77
## Table of Contents
88

99
1. [Requirements](#requirements)
1010
2. [Installation](#installation)
11-
3. Usage
12-
4. Usage With Livewire
13-
5. [Filters](#filters)
14-
6. [Actions & Bulk Actions](#actions--bulk-actions)
15-
7. [Additional Features](#additional-features)
16-
8. [Contributing](#contributing)
17-
9. [License](#license)
11+
3. [Usage With Livewire](#usage-with-livewire)
12+
4. [Filters](#filters)
13+
5. [Actions & Bulk Actions](#actions--bulk-actions)
14+
6. [Additional Features](#additional-features)
15+
7. [Contributing](#contributing)
16+
8. [License](#license)
1817

1918
---
2019

2120
## Requirements
2221

2322
- **PHP 8.2+**
2423
- **Laravel 10.0+**
25-
- **Livewire** *(Optional, only if you need AJAX-driven data tables.)*
24+
- **Livewire** *(Required for usage of this package.)*
2625

2726
---
2827

@@ -42,98 +41,9 @@ Ginkelsoft DataTables is a flexible and easy-to-use package for managing tabular
4241

4342
---
4443

45-
## Usage
46-
47-
You can use this package in a standard Laravel Blade view without Livewire.
48-
49-
### Example
50-
51-
#### Controller:
52-
53-
```php
54-
use Ginkelsoft\DataTables\DataTable;
55-
use Ginkelsoft\DataTables\Column;
56-
use Ginkelsoft\DataTables\Filters\TextFilter;
57-
use Ginkelsoft\DataTables\Filters\SelectFilter;
58-
use Ginkelsoft\DataTables\Filters\DateFilter;
59-
use Ginkelsoft\DataTables\Filters\BooleanFilter;
60-
use App\Models\User;
61-
62-
public function index()
63-
{
64-
$query = User::query();
65-
66-
$datatable = (new DataTable($query))
67-
->setColumns([
68-
Column::make('id', 'ID'),
69-
Column::make('name', 'Name'),
70-
Column::make('email', 'Email'),
71-
])
72-
->setFilters([
73-
new TextFilter('name'),
74-
new SelectFilter('role', null, ['admin' => 'Admin', 'user' => 'User']),
75-
new DateFilter('created_at'),
76-
new BooleanFilter('active')
77-
])
78-
->setPerPage(10);
79-
80-
$rows = $datatable->getRows();
81-
82-
return view('users.index', compact('rows'));
83-
}
84-
```
85-
86-
#### Blade Template:
87-
88-
```blade
89-
<table>
90-
<thead>
91-
<tr>
92-
<th>ID</th>
93-
<th>Name</th>
94-
<th>Email</th>
95-
</tr>
96-
</thead>
97-
<tbody>
98-
@foreach($rows as $row)
99-
<tr>
100-
<td>{{ $row->id }}</td>
101-
<td>{{ $row->name }}</td>
102-
<td>{{ $row->email }}</td>
103-
</tr>
104-
@endforeach
105-
</tbody>
106-
</table>
107-
108-
{{ $rows->links() }}
109-
```
110-
111-
### Actions & Bulk Actions
112-
113-
#### Row Actions:
114-
115-
```blade
116-
@foreach($rows as $row)
117-
<a href="{{ route('users.edit', $row->id) }}" class="bg-blue-500 text-white px-3 py-1 rounded">Edit</a>
118-
<a href="{{ route('users.destroy', $row->id) }}" class="bg-red-500 text-white px-3 py-1 rounded">Delete</a>
119-
@endforeach
120-
```
121-
122-
#### Bulk Actions:
123-
124-
```blade
125-
<form action="{{ route('users.bulk.delete') }}" method="POST">
126-
@csrf
127-
<input type="hidden" name="ids" value="{{ implode(',', $selectedRows) }}">
128-
<button type="submit" class="bg-red-500 text-white px-3 py-1 rounded">Delete Selected</button>
129-
</form>
130-
```
131-
132-
---
133-
13444
## Usage With Livewire
13545

136-
For an **AJAX-driven** workflow with real-time sorting, searching, and pagination:
46+
This package **requires Livewire** and cannot be used without it. To integrate DataTables in your Laravel project, use the following setup:
13747

13848
```blade
13949
<livewire:datatable
@@ -156,6 +66,52 @@ For an **AJAX-driven** workflow with real-time sorting, searching, and paginatio
15666
/>
15767
```
15868

69+
You can now:
70+
71+
- **Search** by typing in the search field.
72+
- **Sort** by clicking column headers.
73+
- **Paginate** without page reload.
74+
- **Select rows** individually or choose to select all.
75+
76+
---
77+
78+
## Filters
79+
80+
You can define various filters for refining results dynamically.
81+
82+
```blade
83+
:filters="[
84+
['column' => 'name', 'type' => 'text'],
85+
['column' => 'role', 'type' => 'select', 'options' => ['admin' => 'Admin', 'user' => 'User']],
86+
['column' => 'created_at', 'type' => 'date'],
87+
['column' => 'active', 'type' => 'boolean']
88+
]"
89+
```
90+
91+
---
92+
93+
## Actions & Bulk Actions
94+
95+
### Row Actions
96+
97+
```blade
98+
:actions="[
99+
['label' => 'Edit', 'route' => 'users.edit', 'class' => 'bg-green-500 text-white px-3 py-1 rounded'],
100+
['label' => 'Delete', 'route' => 'users.destroy', 'class' => 'bg-red-500 text-white px-3 py-1 rounded', 'onclick' => 'return confirm(\'Are you sure?\')']
101+
]"
102+
```
103+
104+
### Bulk Actions
105+
106+
```blade
107+
:bulkActions="[
108+
'delete' => ['label' => 'Delete', 'route' => 'users.bulk.delete'],
109+
'export' => ['label' => 'Export', 'route' => 'users.bulk.export']
110+
]"
111+
```
112+
113+
When multiple rows are selected, the component redirects to the specified route with `ids` in the query/string, so you can handle them in your controller.
114+
159115
---
160116

161117
## Additional Features
@@ -183,4 +139,3 @@ We welcome improvements to code quality, new features, or better documentation.
183139
## License
184140

185141
Ginkelsoft DataTables is open-sourced software licensed under the [MIT license](LICENSE).
186-

0 commit comments

Comments
 (0)