diff --git a/.gitattributes b/.gitattributes index b15bffdc8..8a9c5c832 100644 --- a/.gitattributes +++ b/.gitattributes @@ -32,4 +32,7 @@ /resources/css/laravel-livewire-tables.css export-ignore /resources/css/numberRange.css export-ignore /resources/css/numericSlider.css export-ignore -/resources/css/flatpickr.css export-ignore \ No newline at end of file +/resources/css/flatpickr.css export-ignore +/resources/js/partials/filter-date-range.js export-ignore +/resources/js/partials/filter-number-range.js export-ignore +/resources/js/partials/reorder.js export-ignore diff --git a/CHANGELOG.md b/CHANGELOG.md index d5ebe7647..dbd00df7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## UNRELEASED +- Add capability to set a custom script path for the scripts/styles by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1557 +- Added missing tailwind background colour class for when hovering over the clear button in dark mode by @slakbal in https://github.com/rappasoft/laravel-livewire-tables/pull/1553 +- Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512 +- Revert previous splitting of JS Files + ## [v3.1.3] - 2023-11-03 - Add additional Lifecycle Hook by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534 - SettingColumns/ColumnsSet diff --git a/config/livewire-tables.php b/config/livewire-tables.php index 3dbdf1757..30908f118 100644 --- a/config/livewire-tables.php +++ b/config/livewire-tables.php @@ -30,6 +30,11 @@ */ 'enable_blade_directives ' => false, + /** + * Customise Script & Styles Paths + */ + 'script_base_path' => '/rappasoft/laravel-livewire-tables', + /** * Filter Default Configuration Options * diff --git a/docs/columns/anonymous_columns.md b/docs/columns/anonymous_columns.md new file mode 100644 index 000000000..21bde25dd --- /dev/null +++ b/docs/columns/anonymous_columns.md @@ -0,0 +1,132 @@ +--- +title: Anonymous Columns +weight: 9 +--- + +## Introduction + +Sometimes you may need an "anonymous column", or a column that isn't bound to any column in your database. A common +example of this would be an "actions" column at the end of every row with actions of "view", "edit", and/or "delete". +Though, it doesn't have to be an action column, it could be anything. + +By using an anonymous column, you take full control by using your own view component. So if you find the LinkColumn, +ImageColumn, or any of the other columns too restrictive for your needs, then an anonymous column may be what you need. + +To make an anonymous column, you create an anonymous function that returns a view into the `label()` method, which will +remove the requirement for a database column. Thus, making it "anonymous". You can also pass variables to the view by +chaining the `with()` method onto the `view()` method that gets returned by the anonymous function into the `label()`. +So you can either pass specific values, or the whole row itself. Lastly, chain the `html()` method to the column so it +can render your view component as html. + +## Example Action Column + +Here is an example of an action column using FontAwesome icons for the "view", "edit", and "delete" actions. + +In your `DataTableComponent`: + +```php +setPrimaryKey('id'); + $this->setDefaultSort('id', 'asc'); + } + + public function columns(): array + { + return [ + Column::make('id', 'id') + ->sortable() + ->searchable(), + Column::make('Name', 'name') + ->sortable() + ->searchable(), + Column::make('Email', 'email') + ->sortable() + ->searchable(), + Column::make('Registered', 'created_at') + ->sortable(), + Column::make('Updated', 'updated_at') + ->sortable(), + Column::make('Last Login', 'last_login_at') + ->sortable(), + + Column::make('Action') + ->label( + fn ($row, Column $column) => view('components.livewire.datatables.action-column')->with( + [ + 'viewLink' => route('users.view', $row), + 'editLink' => route('users.edit', $row), + 'deleteLink' => route('users.delete', $row), + ] + ) + )->html(), + ]; + } +} +``` + +NOTE: You don't have to pass individual properties like `viewLink` and so on. You could simply +pass the whole record to your view and handle it however you need within the view file. Example: + +```php +Column::make('Action') + ->label( + fn ($row, Column $column) => view('components.livewire.datatables.action-column')->with([ + 'user' => $row, + ]) + )->html(), +``` + +Now in your component's view file you can do something like this: + +```php +