Merge pull request #1579 from prashant-webkul/development

Datagrid actions enhancement
This commit is contained in:
Jitendra Singh 2019-10-11 11:52:25 +05:30 committed by GitHub
commit db7013be3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 18 deletions

View File

@ -130,6 +130,9 @@ class ProductDataGrid extends DataGrid
public function prepareActions() {
$this->addAction([
'title' => 'Edit Product',
'condition' => function() {
return true;
},
'method' => 'GET', // use GET request only for redirect purposes
'route' => 'admin.catalog.products.edit',
'icon' => 'icon pencil-lg-icon'
@ -149,7 +152,7 @@ class ProductDataGrid extends DataGrid
public function prepareMassActions() {
$this->addMassAction([
'type' => 'delete',
'label' => 'Delete',
'label' => 'Delete',
'action' => route('admin.catalog.products.massdelete'),
'method' => 'DELETE'
]);

View File

@ -42,24 +42,30 @@
<td class="actions" style="width: 100px;" data-value="{{ __('ui::app.datagrid.actions') }}">
<div class="action">
@foreach ($actions as $action)
<a
@if ($action['method'] == 'GET')
href="{{ route($action['route'], $record->{$action['index'] ?? $index}) }}"
@php
$toDisplay = (isset($action['condition']) && gettype($action['condition']) == 'object') ? $action['condition']() : true;
@endphp
@if ($toDisplay)
<a
@if ($action['method'] == 'GET')
href="{{ route($action['route'], $record->{$action['index'] ?? $index}) }}"
@endif
@if ($action['method'] != 'GET')
v-on:click="doAction($event)"
@endif
data-method="{{ $action['method'] }}"
data-action="{{ route($action['route'], $record->{$index}) }}"
data-token="{{ csrf_token() }}"
@if (isset($action['title']))
title="{{ $action['title'] }}"
@endif>
<span class="{{ $action['icon'] }}"></span>
</a>
@endif
@if ($action['method'] != 'GET')
v-on:click="doAction($event)"
@endif
data-method="{{ $action['method'] }}"
data-action="{{ route($action['route'], $record->{$index}) }}"
data-token="{{ csrf_token() }}"
@if (isset($action['title']))
title="{{ $action['title'] }}"
@endif>
<span class="{{ $action['icon'] }}"></span>
</a>
@endforeach
</div>
</td>