Open anonymouse703 opened 3 years ago
I think that you can fix it with: $this->refreshLivewireDatatable(); and build for this a event listner
@pepijndik where to put this $this->refreshLivewireDatatable();?
<?php
namespace App\Http\Livewire;
use App\Models\Permission;
use Mediconesystems\LivewireDatatables\Http\Livewire\LivewireDatatable;
use Mediconesystems\LivewireDatatables\Column;
use Mediconesystems\LivewireDatatables\NumberColumn;
class PermissionDatatable extends LivewireDatatable
{
public $model = Permission::class;
protected $listeners = ['refreshDataTable' => 'refreshTable'];
public function refreshTable()
{
$this->refreshLivewireDatatable();
}
public function columns()
{
return [
NumberColumn::name('id')
->label('ID')
->defaultSort('asc')
->sortBy('id'),
Column::name('name')
->label('Permission')
->searchable(),
Column::delete()
];
}
}
and then call a $this->emit('refreshDataTable') after that you have created the new table element.
<?php namespace App\Http\Livewire; use App\Models\Permission; use Mediconesystems\LivewireDatatables\Http\Livewire\LivewireDatatable; use Mediconesystems\LivewireDatatables\Column; use Mediconesystems\LivewireDatatables\NumberColumn; class PermissionDatatable extends LivewireDatatable { public $model = Permission::class; protected $listeners = ['refreshDataTable' => 'refreshTable']; public function refreshTable() { $this->refreshLivewireDatatable(); } public function columns() { return [ NumberColumn::name('id') ->label('ID') ->defaultSort('asc') ->sortBy('id'), Column::name('name') ->label('Permission') ->searchable(), Column::delete() ]; } }
and then call a $this->emit('refreshDataTable') after that you have created the new table element.
Thanks sir working....
@pepijndik how to add another column name actions where I can put edit and delete button? There's is only Column::delete()
and I don't know how to put the custom column coz when I follow this link https://livewire-datatables.com/actions it's too complex and what I want is something like this like in yajra
->addColumn('actions', function($q) {
return '
<div class="btn-group pull-right" style="border: transparent;">
<a type="button" class="btn btn-success shadow btn-xs sharp mr-1" href="'.url('news-edit/'.$q->id).'" title="Edit News"><i class="fa fa-edit"></i></a>
<form action="'.url('news-delete/'.$q->id).'" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input name="_token" value="' . csrf_token() . '" type="hidden">
<button class="btn btn-info shadow btn-xs sharp mr-1" title="Delete News"><i class="fa fa-trash"></i></button>
</form>
</div>
';
})
@anonymouse703
Just do it like so:
Column::callback(['id'], function ($id) {
return view('quotation::Livewire.TableAction', ['id' => $id]);
})->label('Actie')
and then in your view you can define all your actions. example of mine:
admin.
where did you get this admin.
?
i am using the @/can for my custom gates This is for permissions. Maybe its a good idea to read first the laravel docs about that or at all start with a basics laravel app
Why do I need to refresh the page to see the updated data in the DataTable after I save/store data to the database?
I have three component
Permission Table
and my Form component
and the PermissionDatatable component
and my scripts
and this my view