You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**This package is currently in development and the source is constantly changing, use at your own risk.**
7
+
**This package is still in development and does not have a test suite.**
8
8
9
9
A dynamic Laravel Livewire component for data tables.
10
10
@@ -31,8 +31,8 @@ namespace App\Http\Livewire;
31
31
32
32
use App\User;
33
33
use Illuminate\Database\Eloquent\Builder;
34
-
use Rappasoft\LivewireTables\Http\Livewire\Column;
35
-
use Rappasoft\LivewireTables\Http\Livewire\TableComponent;
34
+
use Rappasoft\LaravelLivewireTables\Views\Column;
35
+
use Rappasoft\LaravelLivewireTables\TableComponent;
36
36
37
37
class UsersTable extends TableComponent
38
38
{
@@ -268,6 +268,147 @@ public function setTableDataId($attribute, $value) : ?string;
268
268
public function setTableDataAttributes($attribute, $value) : array;
269
269
```
270
270
271
+
### Components
272
+
273
+
Along with being able to provide a view to a column, you can use pre-defined components that are built into the package. These are good for when you want to add actions to a column.
274
+
275
+
**Note:** By design using the `components()` method on a column will disable all other functionality (i.e. searching/sorting etc.).
276
+
277
+
#### Defining Components for a Column
278
+
279
+
```php
280
+
Column::make('Actions')
281
+
->components([
282
+
Link::make('Edit'),
283
+
Link::make('Delete'),
284
+
])
285
+
````
286
+
287
+
or
288
+
289
+
```php
290
+
Column::make('Actions')
291
+
->addComponent(Link::make('Edit'))
292
+
->addComponent(Link::make('Delete'))
293
+
````
294
+
295
+
If you would like to hide all the components for a given row, you may pass a callback as the second parameter of the `components()` method:
296
+
297
+
```php
298
+
Column::make('Actions')
299
+
->components([
300
+
Link::make('Edit'),
301
+
Link::make('Delete'),
302
+
], function($model) {
303
+
// Hide the actions for model id 1
304
+
return $model->id === 1;
305
+
})
306
+
````
307
+
308
+
**Note:** You should still assert on the backend that these functions can not be performed on this entity.
309
+
310
+
Building on that, if you would like to pass a custom message to that column when hiding the components for this row, you may pass another callback as the third parameter:
311
+
312
+
```php
313
+
Column::make('Actions')
314
+
->components([
315
+
Link::make('Edit'),
316
+
Link::make('Delete'),
317
+
], function($model) {
318
+
// Hide the actions for model id 1
319
+
return $model->id === 1;
320
+
}, function($model) {
321
+
return __('You can not alter role ' . $model->name . '.');
322
+
})
323
+
````
324
+
325
+
#### Methods
326
+
327
+
Of course two links that don't do anything would be useless, here are a list of methods to be used for the built in components.
328
+
329
+
#### Inherited by all components
330
+
| Method | Usage |
331
+
| -------- | ----- |
332
+
| setAttribute($attribute, $value) | Set an attribute on the component |
333
+
| setAttributes(array $attributes = []) | Set multiple attributes at once |
334
+
| getAttributes() | Get the array of available attributes |
335
+
| setOption($option, $value) | Set an option on the component |
336
+
| setOptions(array $options = []) | Set multiple options at once |
337
+
| getOptions() | Get the array of available options |
338
+
| hideIf($condition) | Hide this component if true |
339
+
| hide() | Hide this component forever |
340
+
| isHidden() | This component is currently hidden |
341
+
342
+
By default all components have access to the `$attributes` and `$options` arrays.
343
+
344
+
#### Link Component
345
+
346
+
| Method | Usage | Type |
347
+
| -------- | ----- | ---- |
348
+
| text($text) | Set the text of the link | string/false |
349
+
| class($class) | Set the html class on the link | string |
350
+
| id($id) | Set the id of the link | string |
351
+
| icon($icon) | Set the icon of the link (font awesome) | string |
352
+
| href(function($model){}) | Set the href of the link | string/callback |
353
+
| view($view) | The view to render for the component | string |
354
+
355
+
#### Button Component
356
+
357
+
| Method | Usage | Type |
358
+
| -------- | ----- | ---- |
359
+
| text($text) | Set the text of the button | string/false |
360
+
| class($class) | Set the html class on the button | string |
361
+
| id($id) | Set the id of the button | string |
362
+
| icon($icon) | Set the icon of the button (font awesome) | string |
363
+
| view($view) | The view to render for the component | string |
364
+
365
+
#### Example
366
+
367
+
This example comes from the upcoming release of my popular [Laravel Boilerplate Project](http://laravel-boilerplate.com). Here we render the roles table in the admin panel.
368
+
369
+
This example uses searching, sorting, relationships, custom attributes, counted relationships, and components:
0 commit comments