Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions resources/views/vendor/datatables/actions.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<div class="flex items-center space-x-2">
@foreach($actions as $action)
<a href="{{ route($action['route'], $row->id) }}"
onclick="event.stopPropagation();"
@foreach($action['attributes'] ?? [] as $key => $value)
{{ $key }}="{{ $value }}"
@foreach($actions as $action)
<a href="{{ isset($action['route']) ? route($action['route'], $row->id) : (isset($action['url']) ? str_replace('{id}', $row->id, $action['url']) : '#') }}"
onclick="event.stopPropagation();"
@foreach($action['attributes'] ?? [] as $key => $value)
{{ $key }}="{{ $value }}"
@endforeach>
{{ $action['label'] }}
</a>
@endforeach
>
{{ $action['label'] }}
</a>
@endforeach
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<label class="text-sm text-gray-600">{{ __('datatable::datatables.bulk_actions') }}</label>
<select wire:model="bulkAction"
class="border border-gray-300 rounded-lg px-3 py-2 text-sm w-48 focus:ring-2 focus:ring-blue-400 transition">
<option value="">-- Selecteer een actie --</option>
<option value="">{{ __('datatable::datatables.select_option') }}</option>
@foreach($bulkActions as $key => $action)
<option value="{{ $key }}">{{ $action['label'] }}</option>
@endforeach
Expand Down
30 changes: 12 additions & 18 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,30 @@ class Action
{
public string $name;
public string $label;
public string $route;
public ?string $route;
public ?string $url;
public array $attributes = [];

/**
* Action constructor.
*
* @param string $name Unique action name.
* @param string $label Button label.
* @param string $route Named route for the action.
* @param array $attributes Additional HTML attributes (e.g., classes, styles).
*/
public function __construct(string $name, string $label, string $route, array $attributes = [])
public function __construct(string $name, string $label, ?string $route = null, ?string $url = null, array $attributes = [])
{
$this->name = $name;
$this->label = $label;
$this->route = $route;
$this->url = $url;
$this->attributes = $attributes;
}

/**
* Factory method to create an action instance.
*
* @param string $name Unique action name.
* @param string $label Button label.
* @param string $route Named route for the action.
* @param array $attributes Additional HTML attributes (e.g., classes, styles).
* @return self
*/
public static function make(string $name, string $label, string $route, array $attributes = []): self
public function toArray(): array
{
return new self($name, $label, $route, $attributes);
return [
'name' => $this->name,
'label' => $this->label,
'route' => $this->route,
'url' => $this->url,
'attributes' => $this->attributes
];
}
}
3 changes: 2 additions & 1 deletion src/Livewire/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ginkelsoft\DataTables\Livewire;

use Ginkelsoft\DataTables\Action;
use Livewire\Component;
use Livewire\WithPagination;
use Ginkelsoft\DataTables\Search;
Expand Down Expand Up @@ -94,7 +95,7 @@ public function mount(
{
$this->model = $model;
$this->columns = $columns;
$this->actions = $actions;
$this->actions = array_map(fn($action) => $action instanceof Action ? $action->toArray() : $action, $actions);
$this->actionsView = $actionsView;
$this->hiddenColumns = $hiddenColumns;
$this->bulkActions = $bulkActions;
Expand Down