Skip to content

Commit

Permalink
Allow columnDefs
Browse files Browse the repository at this point in the history
Group action buttons
  • Loading branch information
rxcod9 committed Dec 21, 2022
1 parent 8b0203a commit 5db58d7
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 40 deletions.
6 changes: 1 addition & 5 deletions resources/views/bread/datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
<input type="checkbox" @if ($showSoftDeleted) checked @endif class="show_soft_deletes" data-toggle="toggle" data-on="{{ __('voyager::bread.soft_deletes_off') }}" data-off="{{ __('voyager::bread.soft_deletes_on') }}">
@endif
@endcan
@foreach($actions as $action)
@if (method_exists($action, 'massAction'))
@include('voyager::bread.partials.actions', ['action' => $action, 'data' => null])
@endif
@endforeach
@include('joy-voyager-datatable::bread.partials.group-actions', ['actions' => $actions, 'dataType' => $dataType, 'data' => null])
@include('voyager::multilingual.language-selector')
</div>
@stop
Expand Down
41 changes: 41 additions & 0 deletions resources/views/bread/partials/group-actions.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@php
$crudActions = collect($actions)->filter(function($action) {
return Str::is([
'*DeleteAction',
'*RestoreAction',
'*EditAction',
'*ViewAction',
'*ExportAction',
], get_class($action));
});
$otherActions = collect($actions)->filter(function($action) {
return !Str::is([
'*DeleteAction',
'*RestoreAction',
'*EditAction',
'*ViewAction',
'*ExportAction',
], get_class($action));
});
@endphp
<div class="btn-group group-actions">
@foreach($crudActions as $action)
@if (method_exists($action, 'massAction'))
@include('voyager::bread.partials.actions', ['action' => $action, 'dataType' => $dataType, 'data' => null])
@endif
@endforeach
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
@foreach($otherActions as $action)
@if (method_exists($action, 'massAction'))
<li>
@include('voyager::bread.partials.actions', ['action' => $action, 'dataType' => $dataType, 'data' => null])
</li>
@endif
@endforeach
</ul>
</ul>
</div>
42 changes: 42 additions & 0 deletions resources/views/bread/partials/single-group-actions.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@php
$crudActions = collect($actions)->filter(function($action) {
return Str::is([
'*DeleteAction',
'*RestoreAction',
'*EditAction',
'*ViewAction',
'*ExportAction',
], get_class($action));
});
$otherActions = collect($actions)->filter(function($action) {
return !Str::is([
'*DeleteAction',
'*RestoreAction',
'*EditAction',
'*ViewAction',
'*ExportAction',
], get_class($action));
});
@endphp
<div class="btn-group single-group-actions btn-group-xs pull-right">
<button type="button" class="btn btn-default dropdown-toggle pull-right" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-left pull-right">
<li class="pull-right">
<div class="btn-group pull-right">
@foreach($otherActions as $action)
@if (!method_exists($action, 'massAction'))
@include('voyager::bread.partials.actions', ['action' => $action, 'dataType' => $dataType, 'data' => $data])
@endif
@endforeach
</div>
</li>
</ul>
@foreach($crudActions as $action)
@if (!method_exists($action, 'massAction'))
@include('voyager::bread.partials.actions', ['action' => $action, 'dataType' => $dataType, 'data' => $data])
@endif
@endforeach
</div>
5 changes: 2 additions & 3 deletions resources/views/components/datatable.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@php
$columnDefs = [
['targets' => 'dt-not-orderable', 'searchable' => false, 'orderable' => false],
];
array_push($columnDefs, ['targets' => 'dt-not-orderable', 'searchable' => false, 'orderable' => false]);
if($withoutCheckbox) {
array_push($columnDefs, ['targets' => 'dt-index', 'visible' => false]);
}
Expand Down Expand Up @@ -70,6 +68,7 @@
var options = {!! json_encode(
array_merge([
"order" => $orderColumn,
"autoWidth" => $autoWidth,
"language" => __('voyager::datatable'),
"columnDefs" => $columnDefs,
"processing" => true,
Expand Down
6 changes: 4 additions & 2 deletions resources/views/components/datatables.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
@foreach($dataTypes as $dataType)
<x-joy-voyager-datatable
:slug="$dataType->slug"
:data-id="($dataId ?? 'tables') . '-' . $dataType->slug"
:with-label="$withLabel"
:auto-width="$autoWidth"
:column-defs="$columnDefs"
:without-checkbox="$withoutCheckbox"
:without-actions="$withoutActions"
:with-label="$withLabel"
:data-id="($dataId ?? 'tables') . '-' . $dataType->slug"
/>
@endforeach
20 changes: 10 additions & 10 deletions src/Services/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,16 @@ public function actions(
$dataType,
$actions
) {
$view = '';
foreach ($actions as $action) {
if (!method_exists($action, 'massAction')) {
$view .= view('voyager::bread.partials.actions', [
'action' => $action,
'dataType' => $dataType,
'data' => $data,
]);
}
$view = 'joy-voyager-datatable::bread.partials.single-group-actions';

if (view()->exists('joy-voyager-datatable::' . $dataType->slug . '.partials.single-group-actions')) {
$view = 'joy-voyager-datatable::' . $dataType->slug . '.partials.single-group-actions';
}
return $view;

return view($view, [
'actions' => $actions,
'dataType' => $dataType,
'data' => $data,
]);
}
}
42 changes: 32 additions & 10 deletions src/View/Components/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@ class Datatable extends Component
protected $slug;

/**
* The dataId.
* The withLabel.
*
* @var string|null
* @var bool|null
*/
protected $dataId;
protected $withLabel;

/**
* The withLabel.
* The autoWidth.
*
* @var bool|null
* @var bool
*/
protected $withLabel;
protected $autoWidth;

/**
* The columnDefs.
*
* @var array
*/
protected $columnDefs;

/**
* The withoutCheckbox.
Expand All @@ -58,31 +65,44 @@ class Datatable extends Component
*/
protected $withoutActions;

/**
* The dataId.
*
* @var string|null
*/
protected $dataId;

/**
* Create the component instance.
*
* @param Request $request
* @param string $slug
* @param bool|null $withLabel
* @param bool $autoWidth
* @param array $columnDefs
* @param bool|null $withoutCheckbox
* @param bool|null $withoutActions
* @param bool|null $withLabel
* @param string|null $dataId
*
* @return void
*/
public function __construct(
Request $request,
string $slug,
?bool $withLabel = null,
?bool $autoWidth = false,
?array $columnDefs = [],
?bool $withoutCheckbox = null,
?bool $withoutActions = null,
?bool $withLabel = null,
?string $dataId = null
) {
$this->request = $request;
$this->slug = $slug;
$this->withLabel = $withLabel;
$this->autoWidth = $autoWidth;
$this->columnDefs = $columnDefs;
$this->withoutCheckbox = $withoutCheckbox;
$this->withoutActions = $withoutActions;
$this->withLabel = $withLabel;
$this->dataId = $dataId;
}

Expand Down Expand Up @@ -176,9 +196,11 @@ public function render()
'usesSoftDeletes' => $usesSoftDeletes,
'showSoftDeleted' => $showSoftDeleted,
'showCheckboxColumn' => $showCheckboxColumn,
'withLabel' => $this->withLabel,
'autoWidth' => $this->autoWidth,
'columnDefs' => $this->columnDefs,
'withoutCheckbox' => $this->withoutCheckbox,
'withoutActions' => $this->withoutActions,
'withLabel' => $this->withLabel,
'dataId' => $this->dataId,
]);
}
Expand Down
43 changes: 33 additions & 10 deletions src/View/Components/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,25 @@ class Datatables extends Component
protected $slugs;

/**
* The dataId.
* The withLabel.
*
* @var string|null
* @var bool|null
*/
protected $dataId;
protected $withLabel;

/**
* The autoWidth.
*
* @var bool
*/
protected $autoWidth;

/**
* The columnDefs.
*
* @var array
*/
protected $columnDefs;

/**
* The withoutCheckbox.
Expand All @@ -45,37 +59,43 @@ class Datatables extends Component
protected $withoutActions;

/**
* The withLabel.
* The dataId.
*
* @var bool|null
* @var string|null
*/
protected $withLabel;
protected $dataId;

/**
* Create the component instance.
*
* @param Request $request
* @param array $slugs
* @param bool|null $withLabel
* @param bool $autoWidth
* @param array $columnDefs
* @param bool|null $withoutCheckbox
* @param bool|null $withoutActions
* @param bool|null $withLabel
* @param string|null $dataId
*
* @return void
*/
public function __construct(
Request $request,
array $slugs = [],
?bool $withLabel = true,
?bool $autoWidth = false,
?array $columnDefs = [],
?bool $withoutCheckbox = true,
?bool $withoutActions = true,
?bool $withLabel = true,
?string $dataId = null
) {
$this->request = $request;
$this->slugs = $slugs;
$this->withLabel = $withLabel;
$this->autoWidth = $autoWidth;
$this->columnDefs = $columnDefs;
$this->withoutCheckbox = $withoutCheckbox;
$this->withoutActions = $withoutActions;
$this->withLabel = $withLabel;
$this->dataId = $dataId;
}

Expand All @@ -95,9 +115,12 @@ public function render()

return Voyager::view($view, [
'dataTypes' => $dataTypes,
'slugs' => $this->slugs,
'withLabel' => $this->withLabel,
'autoWidth' => $this->autoWidth,
'columnDefs' => $this->columnDefs,
'withoutCheckbox' => $this->withoutCheckbox,
'withoutActions' => $this->withoutActions,
'withLabel' => $this->withLabel,
'dataId' => $this->dataId,
]);
}
Expand Down

0 comments on commit 5db58d7

Please sign in to comment.