Skip to content

Commit 3d7eb97

Browse files
committed
- Update readme
1 parent dc03cb2 commit 3d7eb97

File tree

2 files changed

+201
-26
lines changed

2 files changed

+201
-26
lines changed

README.md

Lines changed: 195 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# A Table Component for Laravel Livewire
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/rappasoft/laravel-livewire-tables.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-livewire-tables)
4-
![Run Tests](https://github.com/rappasoft/laravel-livewire-tables/workflows/Run%20Tests/badge.svg?branch=master)
54
[![StyleCI](https://styleci.io/repos/242222088/shield?style=plastic)](https://github.styleci.io/repos/242222088)
6-
[![Code Coverage](https://scrutinizer-ci.com/g/rappasoft/laravel-livewire-tables/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/rappasoft/laravel-livewire-tables/?branch=master)
7-
[![Quality Score](https://img.shields.io/scrutinizer/g/rappasoft/laravel-livewire-tables.svg?style=flat-square)](https://scrutinizer-ci.com/g/rappasoft/laravel-livewire-tables)
85
[![Total Downloads](https://img.shields.io/packagist/dt/rappasoft/laravel-livewire-tables.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-livewire-tables)
96

10-
A Laravel Livewire extension for data tables.
7+
A Laravel Livewire component for data tables.
118

12-
Inspiration from:
9+
**This package is currently in development and the source is constantly changing, use at your own risk.**
1310

14-
[https://github.com/kdion4891/laravel-livewire-tables](https://github.com/kdion4891/laravel-livewire-tables)
11+
Inspiration/Code From:
1512

16-
[https://github.com/yajra/laravel-datatables](https://github.com/yajra/laravel-datatables)
13+
- [https://github.com/kdion4891/laravel-livewire-tables](https://github.com/kdion4891/laravel-livewire-tables)
14+
- [https://github.com/yajra/laravel-datatables](https://github.com/yajra/laravel-datatables)
1715

1816
## Installation
1917

@@ -23,31 +21,208 @@ You can install the package via composer:
2321
composer require rappasoft/laravel-livewire-tables
2422
```
2523

26-
## Version Compatibility
24+
## Usage
2725

28-
Laravel | Livewire Tables
29-
:---------|:----------
30-
7.x | 1.x
26+
### Creating Tables
3127

32-
## Publish
28+
To create a table component you can start with the below stub:
3329

34-
You can publish the configuration file to override the defaults:
30+
```
31+
<?php
32+
33+
namespace App\Http\Livewire;
34+
35+
use App\User;
36+
use Illuminate\Database\Eloquent\Builder;
37+
use Rappasoft\LivewireTables\Http\Livewire\Column;
38+
use Rappasoft\LivewireTables\Http\Livewire\TableComponent;
39+
40+
class UsersTable extends TableComponent
41+
{
42+
43+
public function query() : Builder
44+
{
45+
return User::with('role')
46+
->withCount('permissions');
47+
}
48+
49+
public function columns() : array
50+
{
51+
return [
52+
Column::make('ID')
53+
->searchable()
54+
->sortable(),
55+
Column::make('Name')
56+
->searchable()
57+
->sortable(),
58+
Column::make('E-mail', 'email')
59+
->searchable()
60+
->sortable(),
61+
Column::make('Role', 'role.name')
62+
->searchable()
63+
->sortable(),
64+
Column::make('Permissions', 'permissions_count')
65+
->sortable(),
66+
Column::make('Actions')
67+
->view('backend.auth.user.includes.actions'),
68+
];
69+
}
70+
}
3571
36-
``` bash
37-
php artisan vendor:publish --provider="Rappasoft\LivewireTables\LivewireTablesServiceProvider"
3872
```
3973

40-
## Usage
74+
Your component must implement two methods:
4175

76+
```
77+
/**
78+
* This defines the start of the query, usually Model::query() but can also eagar load relationships and counts.
79+
*/
80+
public function query() : Builder;
81+
82+
/**
83+
* This defines the columns of the table, they don't necessarily have to map to columns on the table.
84+
*/
85+
public function columns() : array;
86+
```
4287

88+
### Defining Columns
4389

44-
### Testing
90+
You can define the columns of your table with the column class:
4591

46-
``` bash
47-
composer test
92+
```
93+
Column::make('Name', 'column_name')
94+
```
95+
96+
The first parameter is the name of the table header. The second parameter is the name of the table column. You can leave blank and the lowercase snake_case version will be used by default.
97+
98+
Here are a list of the column method you can chain to build your columns:
99+
100+
```
101+
/**
102+
* This column is searchable, with no callback it will search the column by name or by the supplied relationship, using a callback overrides the default searching functionality.
103+
*/
104+
public function searchable(callable $callable = null) : self;
105+
106+
/**
107+
* This column is sortable, with no callback it will sort the column by name and sort order defined on the components $sortDirection variable
108+
*/
109+
public function sortable(callable $callable = null) : self;
110+
111+
/**
112+
* The columns output will be put through {!! !!} instead of {{ }}.
113+
*/
114+
public function unescaped() : self;
115+
116+
/**
117+
* The columns output will be put through the Laravel HtmlString class.
118+
*/
119+
public function html() : self;
120+
121+
/**
122+
* This column will not look on the table for the column name, it will look on the model for the given attribute. Useful for custom attributes like getFullNameAttribute: Column::make('Full Name', 'full_name')->customAttribute()
123+
*/
124+
public function customAttribute() : self;
125+
126+
/**
127+
* This view will be used for the column, can still be used with sortable and searchable.
128+
*/
129+
public function view($view) : self;
130+
```
131+
132+
### Properties
133+
134+
You can override any of these in your table component:
135+
136+
#### Table
137+
138+
| Property | Default | Usage |
139+
| -------- | ------- | ----- |
140+
| $tableHeaderEnabled | true | Whether or not to display the table header |
141+
| $tableFooterEnabled | false | Whether or not to display the table footer |
142+
| $tableClass | table table-striped | The class to set on the table |
143+
| $tableHeaderClass | *none* | The class to set on the thead of the table |
144+
| $tableFooterClass | *none* | The class to set on the tfoot of the table |
145+
| $responsive | table-responsive | Tables wrapping div class |
146+
147+
#### Searching
148+
149+
| Property | Default | Usage |
150+
| -------- | ------- | ----- |
151+
| $searchEnabled | true | Whether or not searching is enabled |
152+
| $searchDebounce | 350 | Amount of time in ms to wait to send the search query and refresh the table |
153+
| $disableSearchOnLoading | true | Whether or not to disable the search bar when it is searching/loading new data |
154+
| $search | *none* | The initial search string |
155+
| $searchLabel | Search... | The placeholder for the search box |
156+
| $noResultsMessage | There are no results to display for this query. | The message to display when there are no results |
157+
158+
#### Sorting
159+
160+
| Property | Default | Usage |
161+
| -------- | ------- | ----- |
162+
| $sortField | id | The initial field to be sorting by |
163+
| $sortDirection | asc | The initial direction to sort |
164+
165+
#### Pagination
166+
167+
| Property | Default | Usage |
168+
| -------- | ------- | ----- |
169+
| $paginationEnabled | true | Displays per page and pagination links |
170+
| $perPageOptions | [10, 25, 50] | The options to limit the amount of results per page |
171+
| $perPage | 25 | Amount of items to show per page |
172+
| $perPageLabel | Per Page | The label for the per page filter |
173+
174+
#### Loading
175+
176+
| Property | Default | Usage |
177+
| -------- | ------- | ----- |
178+
| $loadingIndicator | false | Whether or not to show a loading indicator when searching |
179+
| $loadingMessage | Loading... | The loading message that gets displayed |
180+
181+
#### Offline
182+
183+
| Property | Default | Usage |
184+
| -------- | ------- | ----- |
185+
| $offlineIndicator | true | Whether or not to display an offline message when there is no connection |
186+
| $offlineMessage | You are not currently connected to the internet. | The message to display when offline |
187+
188+
#### Checkboxes
189+
190+
| Property | Default | Usage |
191+
| -------- | ------- | ----- |
192+
| $checkbox | false | Whether or not checkboxes are enabled |
193+
| $checkboxLocation | left | The side to put the checkboxes on |
194+
| $checkboxAttribute | id | The model attribute to bind to the checkbox array |
195+
| $checkboxAll | false | Whether or not all checkboxes are currently selected |
196+
| $checkboxValues | [] | The currently selected values of the checkboxes |
197+
198+
#### Other
199+
200+
| Property | Default | Usage |
201+
| -------- | ------- | ----- |
202+
| $wrapperClass | *none* | The classes applied to the wrapper div |
203+
| $refresh | false | Whether or not to refresh the table at a certain interval. false = off, If it's an integer it will be treated as milliseconds (2000 = refresh every 2 seconds), If it's a string it will call that function every 5 seconds.
204+
205+
### Table Methods
206+
207+
```
208+
/**
209+
* Used to set a class on a table header based on the column attribute
210+
*/
211+
public function thClass($attribute) : ?string;
212+
213+
/**
214+
* Used to set a class on a table row
215+
* You have the entre model of the row to work with
216+
*/
217+
public function trClass($model) : ?string;
218+
219+
/**
220+
* Used to set the class of a table cell based on the column and the value of the cell
221+
*/
222+
public function tdClass($attribute, $value) : ?string;
48223
```
49224

50-
### Changelog
225+
## Changelog
51226

52227
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
53228

src/Http/Livewire/Traits/Table.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ trait Table
6262
/**
6363
* @param $attribute
6464
*
65-
* @return |null
65+
* @return string|null
6666
*/
67-
public function thClass($attribute)
67+
public function thClass($attribute) : ?string
6868
{
6969
return null;
7070
}
7171

7272
/**
7373
* @param $model
7474
*
75-
* @return |null
75+
* @return string|null
7676
*/
77-
public function trClass($model)
77+
public function trClass($model) : ?string
7878
{
7979
return null;
8080
}
@@ -83,9 +83,9 @@ public function trClass($model)
8383
* @param $attribute
8484
* @param $value
8585
*
86-
* @return |null
86+
* @return string|null
8787
*/
88-
public function tdClass($attribute, $value)
88+
public function tdClass($attribute, $value) : ?string
8989
{
9090
return null;
9191
}

0 commit comments

Comments
 (0)