Hey! I added action column to datatable and have a vue component for one of actions. But component doesn't compile, just have html tag, but not a component view.
/**
* Load data for datatable
*
* @param string $name
* @return mixed
*/
public function loadData(string $name = 'datatable')
{
$self = $this;
return DataTables::of(static::getData($name))
->addColumn('action', function ($model) use ($self) {
return view('admin._system._partials.datatable.actions', [
'model' => $model,
'resource' => $self
]);
});
}
VIEW (actions.blade.php):
<div class="text-center">
<a href="{{ $resource->getRouteByType('show', $model->id) }}" class="mr-2">
<i class="fa fa-eye"></i>
</a>
<a href="{{ $resource->getRouteByType('edit', $model->id) }}" class="mr-1">
<i class="fa fa-edit"></i>
</a>
<datatable-delete-modal
action="{{ $resource->getRouteByType('destroy', $model->id) }}"
title="{{ $resource->getTitle() }}"
trashed="{{ $model->trashed() }}"
model="{{ $model->toJson() }}"
></datatable-delete-modal>
</div>
When you init Datatables, use initComplete and init Vue again:
<script>
$(function () {
window['dt'] = $('#data-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('admin::resource.data', $resource->getName()) !!}',
columns: {!! $resource->getColumns() !!},
initComplete: (settings, json) => {
new window.Vue({
el: '#app'
});
}
});
});
</script>
Vue component works, but datatables - doesn't
TBH, I haven't tried integrating view events with DT and just fallback to jQuery codes :). Will try this when I got the chance. Keep us posted if you have some progress. Thanks!
I tried to play with my custom vue data-table script again. Try using the gist I created as a ref.
@weijinnx Did you find a workaround for this? I am facing the same issue..
@yajra I have used your custom vue data-table.But the issue still exist.. the component doesn't get compiled! It has to do with ( addColumn functionality I guess ).
@Rux77 I updated the gist and added an example for DeleteButton.vue which is a component added on runtime. Credits to @ChaosPower for helping me on this :).
BTW, action buttons should be compiled/build on the client-side and not the value returned from the server-side. If you find a way to make it work from the server, please share 馃憤
@yajra Thank you so much for this solution. It worked like a charm.
Most helpful comment
@Rux77 I updated the gist and added an example for
DeleteButton.vuewhich is a component added on runtime. Credits to @ChaosPower for helping me on this :).BTW, action buttons should be compiled/build on the client-side and not the value returned from the server-side. If you find a way to make it work from the server, please share 馃憤