Skip to content

Commit

Permalink
Merge pull request #1561 from rappasoft/develop
Browse files Browse the repository at this point in the history
V3 - Develop to Master (3.1.3)
  • Loading branch information
lrljoe authored Nov 19, 2023
2 parents 419c2ff + db0689d commit df31c86
Show file tree
Hide file tree
Showing 24 changed files with 684 additions and 187 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
/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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/livewire-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
*/
'enable_blade_directives ' => false,

/**
* Customise Script & Styles Paths
*/
'script_base_path' => '/rappasoft/laravel-livewire-tables',

/**
* Filter Default Configuration Options
*
Expand Down
132 changes: 132 additions & 0 deletions docs/columns/anonymous_columns.md
Original file line number Diff line number Diff line change
@@ -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
<?php

namespace App\Livewire;

use App\Models\User;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

class UserTable extends DataTableComponent
{
protected $model = User::class;

public function configure(): void
{
$this->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
<div>
@isset ( $viewLink )
<a href="{{ $viewLink }}"><i class="fa-solid fa-eye me-2"></i></a>
@endif

@isset ( $editLink )
<a href="{{ $editLink }}"><i class="fa-solid fa-pen-to-square me-2"></i></a>
@endif

@isset ( $deleteLink )
<form
action="{{ $deleteLink }}"
class="d-inline"
method="POST"
x-data
@submit.prevent="if (confirm('Are you sure you want to delete this user?')) $el.submit()"
>
@method('DELETE')
@csrf
<button type="submit" class="btn btn-link">
<i class="fa-solid fa-trash"></i>
</button>
</form>
@endif
</div>
```

Or, if you passed the whole record, you could use:

```php
<a href="{{ route('users.view', $user) }}"><i class="fa-solid fa-eye me-2"></i></a>
```

## Screenshot

The final result can look something like this:

<img width="1104" alt="users-table-action-column" src="https://github.com/rappasoft/laravel-livewire-tables/assets/9557392/b0432731-c882-45bb-8c53-54a3f485f9a3">
17 changes: 17 additions & 0 deletions docs/columns/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,20 @@ If you are using non-latin characters as the Column Title, you should set a lati
Column::make('地址', 'address.address')
->setCustomSlug('Address')
```

### Hiding Column Label

Labels are visible by default, but should you wish to hide the label from the table header, without impacting on wider table behaviour, you may implement the following method:
```php
Column::make('Name')
->setColumnLabelStatusDisabled()
```

### Displaying Column Label

Labels are visible by default, but should you wish to override a previous "hideColumnLabel()", you may implement the below method:

```php
Column::make('Name')
->setColumnLabelStatusEnabled()
```
15 changes: 14 additions & 1 deletion docs/start/including-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ This is enabled by default, but to re-enable, enable the following options in th
* Enable or Disable automatic injection of third-party assets
*/
'inject_third_party_assets_enabled' => true,

```

#### Changing Script Path

You can change the path used by customising the script_base_path option in the configuration file:

```php
/**
* Customise Script & Styles Paths
*/
'script_base_path' => '/rappasoft/laravel-livewire-tables',
```

### Bundler Including
Expand Down Expand Up @@ -61,4 +73,5 @@ Update the following options in the livewire-tables configuration file, to disab
*/
'enable_blade_directives ' => false,

```
```

Loading

0 comments on commit df31c86

Please sign in to comment.