{"id":13805241,"url":"https://github.com/mediconesystems/livewire-datatables","last_synced_at":"2025-05-14T01:07:26.599Z","repository":{"id":37814070,"uuid":"274180401","full_name":"MedicOneSystems/livewire-datatables","owner":"MedicOneSystems","description":"Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS","archived":false,"fork":false,"pushed_at":"2024-08-12T12:22:25.000Z","size":987,"stargazers_count":1193,"open_issues_count":192,"forks_count":258,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-10-29T09:20:52.545Z","etag":null,"topics":["laravel","laravel-livewire","livewire-datatables","tailwind"],"latest_commit_sha":null,"homepage":"https://livewire-datatables.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MedicOneSystems.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-22T15:50:38.000Z","updated_at":"2024-10-26T17:01:46.000Z","dependencies_parsed_at":"2024-01-16T21:11:46.430Z","dependency_job_id":"10ef0879-fbfc-442c-8679-18713bc4d5f9","html_url":"https://github.com/MedicOneSystems/livewire-datatables","commit_stats":{"total_commits":267,"total_committers":73,"mean_commits":"3.6575342465753424","dds":0.6853932584269663,"last_synced_commit":"a1db74d1a5e04cbb369e131e7520d4a950a70a75"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MedicOneSystems%2Flivewire-datatables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MedicOneSystems%2Flivewire-datatables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MedicOneSystems%2Flivewire-datatables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MedicOneSystems%2Flivewire-datatables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MedicOneSystems","download_url":"https://codeload.github.com/MedicOneSystems/livewire-datatables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247934841,"owners_count":21020729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-livewire","livewire-datatables","tailwind"],"created_at":"2024-08-04T01:00:59.029Z","updated_at":"2025-04-08T22:19:14.109Z","avatar_url":"https://github.com/MedicOneSystems.png","language":"PHP","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# Livewire Datatables\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/mediconesystems/livewire-datatables.svg?style=flat-square)](https://packagist.org/packages/mediconesystems/livewire-datatables)\n[![Total Downloads](https://img.shields.io/packagist/dt/mediconesystems/livewire-datatables.svg?style=flat-square)](https://packagist.org/packages/mediconesystems/livewire-datatables)\n\n### Features\n- Use a model or query builder to supply data\n- Mutate and format columns using preset or custom callbacks\n- Sort data using column or computed column\n- Filter using booleans, times, dates, selects or free text\n- Create complex combined filters using the [complex query builder](#complex-query-builder)\n- Show / hide columns\n- Column groups\n- Mass Action (Bulk) Support\n\n## [Demo App Repo](https://github.com/MedicOneSystems/demo-livewire-datatables)\n\n![screenshot](resources/images/screenshot.png \"Screenshot\")\n\n## Requirements\n- [Laravel 7, 8 or 9](https://laravel.com/docs/9.x)\n- [Livewire](https://laravel-livewire.com/)\n- [Tailwind](https://tailwindcss.com/)\n- [Alpine JS](https://github.com/alpinejs/alpine)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require mediconesystems/livewire-datatables\n```\nIf you use laravel 9 first execute\n```bash\ncomposer require psr/simple-cache:^1.0 maatwebsite/excel\n```\n\n### Optional\nYou don't need to, but if you like you can publish the config file and blade template assets:\n```bash\nphp artisan vendor:publish --provider=\"Mediconesystems\\LivewireDatatables\\LivewireDatatablesServiceProvider\"\n```\nThis will enable you to modify the blade views and apply your own styling, the datatables views will be published to resources/livewire/datatables. The config file contains the default time and date formats used throughout\n\u003e - This can be useful if you're using Purge CSS on your project, to make sure all the livewire-datatables classes get included\n\nSeveral of the built-in dynamic components use Alpine JS, so to remove flickers on page load, make sure you have\n```css\n[x-cloak] {\n    display: none;\n}\n```\nsomewhere in your CSS\n\n## Basic Usage\n\n- Use the ```livewire-datatable``` component in your blade view, and pass in a model:\n```html\n...\n\n\u003clivewire:datatable model=\"App\\User\" name=\"all-users\" /\u003e\n\n...\n```\n\n## Template Syntax\n- There are many ways to modify the table by passing additional properties into the component:\n```html\n\u003clivewire:datatable\n    model=\"App\\User\"\n    name=\"users\"\n    include=\"id, name, dob, created_at\"\n    dates=\"dob\"\n/\u003e\n```\n\n*Attention*: Please note that having multiple datatables on the same page _or_ more than one datatable of the same\ntype on different pages needs to have a unique `name` attribute assigned to each one so they do not conflict with each\nother as in the example above.\n\n### Props\n| Property | Arguments | Result                                                                                                                                         | Example |\n|----|----|------------------------------------------------------------------------------------------------------------------------------------------------|----|\n|**model**|*String* full model name| Define the base model for the table                                                                                                            | ```model=\"App\\Post\"```|\n|**include**|*String\\| Array* of column definitions                                                                                                                   |specify columns to be shown in table, label can be specified by using \\| delimter | ```include=\"name, email, dob\\|Birth Date, role\"```|\n|**exclude**|*String\\| Array* of column definitions                                                                                                                   |columns are excluded from table| ```:exclude=\"['created_at', 'updated_at']\"```|\n|**hide**|*String\\| Array* of column definitions                                                                                                                   |columns are present, but start hidden|```hidden=\"email_verified_at\"```|\n|**dates**|*String\\| Array* of column definitions [ and optional format in \\                                                                                        | delimited string]|column values are formatted as per the default date format, or format can be included in string with \\| separator | ```:dates=\"['dob\\|lS F y', 'created_at']\"```|\n|**times**|*String\\| Array* of column definitions [optional format in \\                                                                                             | delimited string]|column values are formatted as per the default time format, or format can be included in string with \\| separator | ```'bedtime\\|g:i A'```|\n|**searchable**|*String\\| Array* of column names                                                                                                                         | Defines columns to be included in global search | ```searchable=\"name, email\"```|\n|**sort**|*String* of column definition [and optional 'asc' or 'desc' (default: 'desc') in \\| delimited string]                                                                                                                              |Specifies the column and direction for initial table sort. Default is column 0 descending | ```sort=\"name\\|asc\"```|\n|**hide-header**|*Boolean* default: *false*| The top row of the table including the column titles is removed if this is ```true```                                                          | |\n|**hide-pagination**|*Boolean* default: *false*| Pagination controls are removed if this is ```true```                                                                                          | |\n|**per-page**|*Integer* default: 10| Number of rows per page                                                                                                                        | ```per-page=\"20\"``` |\n|**exportable**|*Boolean*  default: *false*| Allows table to be exported                                                                                                                    | ```\u003clivewire:datatable model=\"App/Post\" exportable /\u003e``` |\n|**hideable**| _String_ | gives ability to show/hide columns, accepts strings 'inline', 'buttons', or 'select'                                                           | ```\u003clivewire:datatable model=\"App/Post\" hideable=\"inline\" /\u003e``` |\n|**buttonsSlot**| _String_ | blade view to be included immediately after the buttons at the top of the table in the component, which can therefore access public properties |  |\n|**beforeTableSlot**| _String_ | blade view to be included immediately before the table in the component, which can therefore access public properties                          |  |\n|**afterTableSlot**| _String_ | blade view to be included immediately after the table in the component, which can therefore access public properties                           | [demo](https://livewire-datatables.com/complex) |\n---\n\n\n## Component Syntax\n\n### Create a livewire component that extends ```Mediconesystems\\LivewireDatatables\\LivewireDatatable```\n\u003e ```php artisan make:livewire-datatable foo``` --\u003e 'app/Http/Livewire/Foo.php'\n\n\u003e ```php artisan make:livewire-datatable tables.bar``` --\u003e 'app/Http/Livewire/Tables/Bar.php'\n\n### Provide a datasource by declaring public property ```$model``` **OR** public method ```builder()``` that returns an instance of ```Illuminate\\Database\\Eloquent\\Builder```\n\u003e ```php artisan make:livewire-datatable users-table --model=user``` --\u003e 'app/Http/Livewire/UsersTable.php' with ```public $model = User::class```\n\n### Declare a public method ```columns``` that returns an array containing one or more ```Mediconesystems\\LivewireDatatables\\Column```\n\n## Columns\nColumns can be built using any of the static methods below, and then their attributes assigned using fluent method chains.\nThere are additional specific types of Column; ```NumberColumn```, ```DateColumn```, ```TimeColumn```, using the correct one for your datatype will enable type-specific formatting and filtering:\n\n| Class | Description |\n|---|---|\n|Column|Generic string-based column. Filter will be a text input|\n|NumberColumn| Number-based column. Filters will be a numeric range|\n|BooleanColumn| Values will be automatically formatted to a yes/no icon, filters will be yes/no|\n|DateColumn| Values will be automatically formatted to the default date format. Filters will be a date range|\n|TimeColumn| Values will be automatically formatted to the default time format. Filters will be a time range|\n|LabelColumn| Fixed header string (\"label\") with fixed content string in every row. No SQL is executed at all|\n___\n\n```php\nclass ComplexDemoTable extends LivewireDatatable\n{\n\n    public function builder()\n    {\n        return User::query();\n    }\n\n    public function columns()\n    {\n        return [\n            NumberColumn::name('id')\n                -\u003elabel('ID')\n                -\u003elinkTo('job', 6),\n\n            BooleanColumn::name('email_verified_at')\n                -\u003elabel('Email Verified')\n                -\u003eformat()\n                -\u003efilterable(),\n\n            Column::name('name')\n                -\u003edefaultSort('asc')\n                -\u003egroup('group1')\n                -\u003esearchable()\n                -\u003ehideable()\n                -\u003efilterable(),\n\n            Column::name('planet.name')\n                -\u003elabel('Planet')\n                -\u003egroup('group1')\n                -\u003esearchable()\n                -\u003ehideable()\n                -\u003efilterable($this-\u003eplanets),\n\n            // Column that counts every line from 1 upwards, independent of content\n            Column::index($this);\n\n            DateColumn::name('dob')\n                -\u003elabel('DOB')\n                -\u003egroup('group2')\n                -\u003efilterable()\n                -\u003ehide(),\n\n            (new LabelColumn())\n                -\u003elabel('My custom heading')\n                -\u003econtent('This fixed string appears in every row'),\n\n            NumberColumn::name('dollars_spent')\n                -\u003eenableSummary(),\n        ];\n    }\n}\n```\n\n### Column Methods\n| Method | Arguments | Result | Example |\n|----|----|----|----|\n|_static_ **name**| *String* $column |Builds a column from column definition, which can be eith Eloquent or SQL dot notation (see below) |```Column::name('name')```|\n|_static_ **raw**| *String* $rawSqlStatement|Builds a column from raw SQL statement. Must include \"... AS _alias_\"|```Column::raw(\"CONCAT(ROUND(DATEDIFF(NOW(), users.dob) / planets.orbital_period, 1) AS `Native Age`\")```|\n|_static_ **callback**|*Array\\|String* $columns, *Closure\\|String* $callback| Passes the columns from the first argument into the callback to allow custom mutations. The callback can be a method on the table class, or inline | _(see below)_|\n|_static_ **scope**|*String* $scope, *String* $alias|Builds a column from a scope on the parent model|```Column::scope('selectLastLogin', 'Last Login')```|\n|_static_ **delete**|[*String* $primaryKey default: 'id']|Adds a column with a delete button, which will call ```$this-\u003emodel::destroy($primaryKey)```|```Column::delete()```|\n|_static_ **checkbox**|[*String* $column default: 'id']|Adds a column with a checkbox. The component public property ```$selected``` will contain an array of the named column from checked rows, |```Column::checkbox()```|\n|**label**|*String* $name|Changes the display name of a column|```Column::name('id')-\u003elabel('ID)```|\n|**group**|*String* $group|Assign the column to a group. Allows to toggle the visibility of all columns of a group at once|```Column::name('id')-\u003egroup('my-group')```|\n|**format**|[*String* $format]|Formats the column value according to type. Dates/times will use the default format or the argument |```Column::name('email_verified_at')-\u003efilterable(),```|\n|**hide**| |Marks column to start as hidden|```Column::name('id')-\u003ehidden()```|\n|**sortBy**|*String\\|Expression* $column|Changes the query by which the column is sorted|```Column::name('dob')-\u003esortBy('DATE_FORMAT(users.dob, \"%m%d%Y\")'),```|\n|**truncate**|[*Integer* $length (default: 16)]Truncates column to $length and provides full-text in a tooltip. Uses ```view('livewire-datatables::tooltip)```|```Column::name('biography)-\u003etruncate(30)```|\n|**linkTo**|*String* $model, [*Integer* $pad]|Replaces the value with a link to ```\"/$model/$value\"```. Useful for ID columns. Optional zero-padding. Uses ```view('livewire-datatables::link)```|```Column::name('id')-\u003elinkTo('user')```|\n|**link**|*String* $href, [*String* $slot]|Let the content of the column render as a link. You may use {{ }} syntax to fill the url with any attributes of the current row. Uses ```view('livewire-datatables::link)```|```Column::name('first_name')-\u003elink('/users/{{slug}}/edit', 'edit {{first_name}} {{last_name}}')```|\n|**round**|[*Integer* $precision (default: 0)]|Rounds value to given precision|```Column::name('age')-\u003eround()```|\n|**defaultSort**|[*String* $direction (default: 'desc')]|Marks the column as the default search column|```Column::name('name')-\u003edefaultSort('asc')```|\n|**searchable**| |Includes the column in the global search|```Column::name('name')-\u003esearchable()```|\n|**hideable**| |The user is able to toggle the visibility of this column|```Column::name('name')-\u003ehideable()```|\n|**filterable**|[*Array* $options], [*String* $filterScope]|Adds a filter to the column, according to Column type. If an array of options is passed it wil be used to populate a select input. If the column is a scope column then the name of the filter scope must also be passed|```Column::name('allegiance')-\u003efilterable(['Rebellion', 'Empire'])```|\n|**unwrap**| | Prevents the content of the column from being wrapped in multiple lines |```Column::name('oneliner')-\u003eunwrap()```|\n|**filterOn**|*String/Array* $statement|Allows you to specify a column name or sql statement upon which to perform the filter (must use SQL syntax, not Eloquent eg. ```'users.name'``` instead of ```'user.name'```). Useful if using a callback to modify the displayed values. Can pass a single string or array of strings which will be combined with ```OR```|```Column::callback(['name', 'allegiance'], function ($name, $allegiance) { return \"$name is allied to $allegiance\"; })-\u003efilterable(['Rebellion', 'Empire'])-\u003efilterOn('users.allegiance')```|\n|**view**|*String* $viewName| Passes the column value, whole row of values, and any additional parameters to a view template | _(see below)_|\n|**editable**| | Marks the column as editable | _(see below)_|\n|**alignCenter**| | Center-aligns column header _and_ contents |```Column::delete()-\u003ealignCenter()```|\n|**alignRight**| | Right-aligns column header _and_ contents |```Column::delete()-\u003ealignRight()```|\n|**contentAlignCenter**| | Center-aligns column contents |```Column::delete()-\u003econtentAlignCenter()```|\n|**contentAlignRight**| | Right-aligns column contents |```Column::delete()-\u003econtentAlignRight()```|\n|**headerAlignCenter**| | Center-aligns column header |```Column::delete()-\u003eheaderAlignCenter()```|\n|**headerAlignRight**| | Right-aligns column header |```Column::delete()-\u003eheaderAlignRight()```|\n|**editable**| | Marks the column as editable | _(see below)_|\n|**exportCallback**| Closure $callback | Reformats the result when exporting | _(see below)_ |\n|**excludeFromExport**| | Excludes the column from export |```Column::name('email')-\u003eexcludeFromExport()```|\n|**unsortable**| | Prevents the column being sortable |```Column::name('email')-\u003eunsortable()```|\n___\n\n### Listener\nThe component will listen for the ```refreshLivewireDatatable``` event, which allows you to refresh the table from external components.\n\n### Eloquent Column Names\nColumns from Eloquent relations can be included using the normal eloquent dot notation, eg. ```planet.name```, Livewire Datatables will automatically add the necessary table joins to include the column. If the relationship is of a 'many' type (```HasMany```, ```BelongsToMany```, ```HasManyThrough```) then Livewire Datatables will create an aggregated subquery (which is much more efficient than a join and group. Thanks [@reinink](https://eloquent-course.reinink.ca/)). By default, the aggregate type will be ```count``` for a numeric column and ```group_concat``` for a string column, but this can be over-ridden using a colon delimeter;\n\n```php\nNumberColumn::name('students.age:sum')-\u003elabel('Student Sum'),\n\nNumberColumn::name('students.age:avg')-\u003elabel('Student Avg'),\n\nNumberColumn::name('students.age:min')-\u003elabel('Student Min'),\n\nNumberColumn::name('students.age:max')-\u003elabel('Student Max'),\n```\n\n### Column Groups\n\nWhen you have a very big table with a lot of columns, it is possible to create 'column groups' that allows the user to toggle the visibility of a whole group at once. Use `-\u003egroup('NAME')` at any column to achieve this.\nYou can human readable labels and translations of your groups via the `groupLabels` property of your table:\n\n```php\nclass GroupDemoTable extends LivewireDatatable\n{\n    public $groupLabels = [\n         'group1' =\u003e 'app.translation_for_group_1'\n         'group2' =\u003e 'app.translation_for_group_2'\n    ];\n\npublic function columns()\n{\n    return [\n        Column::name('planets.name')\n            -\u003egroup('group1')\n            -\u003elabel('Planet'),\n\n        Column::name('planets.name')\n            -\u003egroup('group2')\n            -\u003elabel('Planet'),\n```\n\n### Summary row\nIf you need to summarize all cells of a specific column, you can use `enableSummary()`:\n\n```php\npublic function columns()\n{\n    return [\n        Column::name('dollars_spent')\n            -\u003elabel('Expenses in Dollar')\n            -\u003eenableSummary(),\n\n        Column::name('euro_spent')\n            -\u003elabel('Expenses in Euro')\n            -\u003eenableSummary(),\n```\n\n### Mass (Bulk) Action\n\nIf you want to be able to act upon several records at once, you can use the `buildActions()` method in your Table:\n\n```php\npublic function buildActions()\n    {\n        return [\n\n            Action::value('edit')-\u003elabel('Edit Selected')-\u003egroup('Default Options')-\u003ecallback(function ($mode, $items) {\n                // $items contains an array with the primary keys of the selected items\n            }),\n\n            Action::value('update')-\u003elabel('Update Selected')-\u003egroup('Default Options')-\u003ecallback(function ($mode, $items) {\n                // $items contains an array with the primary keys of the selected items\n            }),\n\n            Action::groupBy('Export Options', function () {\n                return [\n                    Action::value('csv')-\u003elabel('Export CSV')-\u003eexport('SalesOrders.csv'),\n                    Action::value('html')-\u003elabel('Export HTML')-\u003eexport('SalesOrders.html'),\n                    Action::value('xlsx')-\u003elabel('Export XLSX')-\u003eexport('SalesOrders.xlsx')-\u003estyles($this-\u003eexportStyles)-\u003ewidths($this-\u003eexportWidths)\n                ];\n            }),\n        ];\n    }\n```\n\n### Mass Action Style\n\nIf you only have small style adjustments to the Bulk Action Dropdown you can adjust some settings here:\n\n```php\npublic function getExportStylesProperty()\n    {\n        return [\n            '1'  =\u003e ['font' =\u003e ['bold' =\u003e true]],\n            'B2' =\u003e ['font' =\u003e ['italic' =\u003e true]],\n            'C'  =\u003e ['font' =\u003e ['size' =\u003e 16]],\n        ];\n    }\n\n    public function getExportWidthsProperty()\n    {\n        return [\n            'A' =\u003e 55,\n            'B' =\u003e 45,\n        ];\n    }\n```\n\n### Pin Records\n\nIf you want to give your users the ability to pin specific records to be able to, for example, compare\nthem with each other, you can use the CanPinRecords trait. Ensure to have at least one Checkbox Column\nso the user can select records:\n\n```php\nuse Mediconesystems\\LivewireDatatables\\Traits\\CanPinRecords;\n\nclass RecordTable extends LivewireDatatable\n{\n    use CanPinRecords;\n\n    public $model = Record::class;\n\n    public function columns()\n    {\n        return [\n            Column::checkbox(),\n\n            // ...\n\n```\n\n### Custom column names\nIt is still possible to take full control over your table, you can define a ```builder``` method using whatever query you like, using your own joins, groups whatever, and then name your columns using your normal SQL syntax:\n\n```php\n\npublic function builder()\n{\n    return User::query()\n        -\u003eleftJoin('planets', 'planets.id', 'users.planet_id')\n        -\u003eleftJoin('moons', 'moons.id', 'planets.moon_id')\n        -\u003egroupBy('users.id');\n}\n\npublic function columns()\n{\n    return [\n        NumberColumn::name('id')\n            -\u003efilterable(),\n\n        Column::name('planets.name')\n            -\u003elabel('Planet'),\n\n        Column::raw('GROUP_CONCAT(planets.name SEPARATOR \" | \") AS `Moon`'),\n\n        ...\n}\n\n```\n\n### Callbacks\nCallbacks give you the freedom to perform any mutations you like on the data before displaying in the table.\n- The callbacks are performed on the paginated results of the database query, so shouldn't use a ton of memory\n- Callbacks will receive the chosen columns as their arguments.\n- Callbacks can be defined inline as below, or as public methods on the Datatable class, referenced by passing the name as a string as the second argument to the callback method.\n- If you want to format the result differently for export, use ```-\u003eexportCallback(Closure $callback)```.\n```php\nclass CallbackDemoTable extends LivewireDatatable\n{\n    public model = User::class\n\n    public function columns()\n    {\n        return [\n            Column::name('users.id'),\n\n            Column::name('users.dob')-\u003eformat(),\n\n            Column::callback(['dob', 'signup_date'], function ($dob, $signupDate) {\n                $age = $signupDate-\u003ediffInYears($dob);\n                return $age \u003e 18\n                    ? '\u003cspan class=\"text-red-500\"\u003e' . $age . '\u003c/span\u003e'\n                    : $age;\n            })-\u003eexportCallback(function ($dob, $signupDate), {\n                return $age = $signupDate-\u003ediffInYears($dob);\n            }),\n\n            ...\n    }\n}\n```\n\n### Default Filters\n\nIf you want to have a default filter applied to your table, you can use the `defaultFilters` property. The `defaultFilter` should be an Array of column names and the default filter value to use for. When a persisted filter (`$this-\u003epersistFilters` is true and session values are available) is available, it will override the default filters.\n\nIn the example below, the table will by default be filtered by rows where the _deleted_at_ column is false. If the user has a persisted filter for the _deleted_at_ column, the default filter will be ignored.\n\n```php\nclass CallbackDemoTable extends LivewireDatatable\n{\n    public $defaultFilters = [\n        'deleted_at' =\u003e '0',\n    ];\n\n    public function builder()\n    {\n        return User::query()-\u003ewithTrashed();\n    }\n\n    public function columns()\n    {\n        return [\n            Column::name('id'),\n            BooleanColumn::name('deleted_at')-\u003efilterable(),\n        ];\n    }\n}\n```\n\n### Views\nYou can specify that a column's output is piped directly into a separate blade view template.\n- Template is specified using ususal laravel view helper syntax\n- Views will receive the column's value as ```$value```, and the whole query row as ```$row```\n```php\nclass CallbackDemoTable extends LivewireDatatable\n{\n    public model = User::class\n\n    public function columns()\n    {\n        return [\n            Column::name('users.id'),\n\n            Column::name('users.dob')-\u003eview('tables.dateview'),\n\n            Column::name('users.signup_date')-\u003eformat(),\n        ];\n    }\n```\n```html\n'tables/dateview.blade.php'\n\u003cspan class=\"mx-4 my-2 bg-pink-500\"\u003e\n    \u003cx-date-thing :value=\"$value\" /\u003e\n\u003c/span\u003e\n```\n\n### Editable Columns\nYou can mark a column as editable using ```editable```\nThis uses the ```view()``` method above to pass the data into an Alpine/Livewire compnent that can directly update the underlying database data. Requires the column to have ```column``` defined using standard Laravel naming. This is included as an example. Much more comprehensive custom editable columns with validation etc can be built using the callback or view methods above.\n\n```php\nclass EditableTable extends LivewireDatatable\n{\n\n    public $model = User::class;\n\n    public function columns()\n    {\n        return [\n            Column::name('id')\n                -\u003elabel('ID')\n                -\u003elinkTo('job', 6),\n\n            Column::name('email')\n                -\u003eeditable(),\n\n            ...\n        ];\n    }\n}\n```\n\n# Complex Query Builder\nJust add ```$complex = true``` to your Datatable Class and all filterable columns will be available in the complex query builder.\n\n**Features**\n- Combine rules and groups of rules using AND/OR logic\n- Drag and drop rules around the interface\n\n![image](https://user-images.githubusercontent.com/7000886/128855344-25035758-ca90-42d2-bd19-518c9de45148.png)\n---\n**Persisting Queries** (Requires AlpineJS v3 with $persist plugin)\n- Add ```$persistComplexQuery = true``` to your class and queries will be stored in browser localstorage.\n- By default the localstorage key will be the class name. You can provide your own by setting the public property ```$persistKey``` or overriding ```getPersistKeyProperty()``` on the Datatable Class\n- eg: for user-specific persistence:\n\n```php\npublic function getPersistKeyProperty()\n{\n    return Auth::id() . '-' . parent::getPersistKeyProperty();\n}\n```\n---\n**Saving Queries**\n\nIf you want to permanently save queries you must provide 3 methods for adding, deleting and retrieving your saved queries using whatever logic you like:\n\n- ```public function saveQuery(String $name, Array $rules)```\n- ```public function deleteQuery(Int $id)```\n- ```public function getSavedQueries()```\n\n* In your save and delete methods, be sure to emit an ```updateSavedQueries``` livewire event and pass a fresh array of results (see example below)\n\n### Example:\nThis example shows saving queries using a conventional Laravel ComplexQuery model, that belongsTo a User\n\n```php\n/* Migration */\n\nclass CreateComplexQueriesTable extends Migration\n{\n    public function up()\n    {\n        Schema::create('complex_queries', function (Blueprint $table) {\n            $table-\u003eid();\n            $table-\u003eunsignedInteger('user_id');\n            $table-\u003estring('table');\n            $table-\u003ejson('rules');\n            $table-\u003estring('name');\n            $table-\u003etimestamps();\n        });\n    }\n}\n\n\n/* Model */\n\nclass ComplexQuery extends BaseModel\n{\n    protected $casts = ['rules' =\u003e 'array'];\n\n    public function user()\n    {\n        return $this-\u003ebelongsTo(User::class);\n    }\n}\n\n/* Datatable Class */\n\nclass TableWithSaving extends LivewireDatatable\n{\n    ...\n\n    public function saveQuery($name, $rules)\n    {\n        Auth::user()-\u003ecomplex_queries()-\u003ecreate([\n            'table' =\u003e $this-\u003ename,\n            'name' =\u003e $name,\n            'rules' =\u003e $rules\n        ]);\n\n        $this-\u003eemit('updateSavedQueries', $this-\u003egetSavedQueries());\n    }\n\n    public function deleteQuery($id)\n    {\n        ComplexQuery::destroy($id);\n\n        $this-\u003eemit('updateSavedQueries', $this-\u003egetSavedQueries());\n    }\n\n    public function getSavedQueries()\n    {\n        return Auth::user()-\u003ecomplex_queries()-\u003ewhere('table', $this-\u003ename)-\u003eget();\n    }\n\n    ...\n}\n```\n\n\n# Styling\nI know it's not cool to provide a package with tons of opionated markup and styling. Most other packages seem to have gone down the route of passing optional classes around as arguments or config variables. My take is that because this is just blade with tailwind, you can publish the templates and do whatever you like to them - it should be obvious where the Livewire and Alpine moving parts are.\n\nThere are methods for applying styles to rows and cells. ```rowClasses``` receives the ```$row``` and the [laravel loop variable](https://laravel.com/docs/8.x/blade#the-loop-variable) as parameters. ```cellClasses``` receives the ```$row``` and ```$column```\n\nFor example:\n```php\npublic function rowClasses($row, $loop)\n{\n    return 'divide-x divide-gray-100 text-sm text-gray-900 ' . ($this-\u003erowIsSelected($row) ? 'bg-yellow-100' : ($row-\u003e{'car.model'} === 'Ferrari' ? 'bg-red-500' : ($loop-\u003eeven ? 'bg-gray-100' : 'bg-gray-50')));\n}\n\npublic function cellClasses($row, $column)\n{\n    return 'text-sm ' . ($this-\u003erowIsSelected($row) ? ' text-gray-900' : ($row-\u003e{'car.model'} === 'Ferrari' ? ' text-white' : ' text-gray-900'));\n}\n```\n\nYou can change the default CSS classes applied by the ```rowClasses``` and the ```cellClasses``` methods by changing ```default_classes``` in the ```livewire-datatables.php``` config file.\n\nYou could also override the render method in your table's class to provide different templates for different tables.\n\n\n## Credits and Influences\n- [Laravel](https://laravel.com/)\n- [Laravel Livewire](https://laravel-livewire.com/docs/quickstart/)\n- [Tailwind CSS](https://tailwindcss.com/)\n- [AlpineJS](https://github.com/alpinejs/alpine)\n- [livewire-tables by coryrose1](https://github.com/coryrose1/livewire-tables)\n- [laravel-livewire-datatables by kdion4891](https://github.com/kdion4891/laravel-livewire-tables)\n- [Jonathan Reinink\\'s Eloquent course](https://eloquent-course.reinink.ca/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediconesystems%2Flivewire-datatables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediconesystems%2Flivewire-datatables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediconesystems%2Flivewire-datatables/lists"}