-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model popup using AJAX to show current contents and icon change #5701
Comments
Was curious about this too and here's what I've found. In the last case, no render will be called during the Grid render, but ajax load using It will pass to your Renderable the "key" (primaryKey / id) of the current row, and everything else is just similar to what you do in the callback with tiny adjustments. For example: class PostFilesRenderable implements \Illuminate\Contracts\Support\Renderable {
public function render() {
$files = File::query()->select(['id', 'path'])->where('post_id', request('key'))->get()->map(function($item) {
$item->size = file_size(\Illuminate\Support\Facades\Storage::disk('admin')->size($item->path));
return $item;
});
$table = new \Encore\Admin\Widgets\Table(['ID', 'Path', 'Size'], $files->toArray());
return $table->render() . "<h4>Total files: " . $files->count() . "</h4>";
}
} Your controller's grid: $grid->column('files')->model('Files', PostFilesRenderable); |
As to "fa-clone" icon change - it's hardcoded into In your app('view')->prependNamespace('admin', resource_path('views/vendor/laravel-admin')); You need to follow the same dir structure, so for @if ($value == 0)
<span data-toggle="modal" data-target="#grid-modal-{{ $name }}" data-key="{{ $key }}">
<a href="javascript:void(0)"><i class="fa fa-eye"></i> {{ $value }}</a>
</span>
@else
<span> --- </span>
@endif OR you can just simply don't display anything for the column if you don't want to, depending on the original value: $grid->column('files')->model('Files', PostFilesRenderable)
->display(function (string $c, Grid\Column $column) {
return $column->getOriginal() ? $c : '---';
}); |
Hi @alexoleynik0 thanks for these directions, it help me in achieving goal. I was busy, when you suggest. Today i spare time to implement it. but there are a couple of things that i face, so i wants to share, it may help others.
regarding icon instead of copying view i use the struct you provided to control display
in my case for notes i also count notes available as notes_count, as follow
Thank you for your help. |
Description:
I am using Grid Column Model to load Related Notes, but unfortunately it has 2 issues
Steps To Reproduce:
`$grid->column('notes', __('Notes'))->display(function ($title, $column) {
$notes = $this->notes()->with('admin:id,name')->take(10)->orderBy('id','desc')->get()->map(function ($note) {
//return $note->only(['id','description','admin_user_id' , 'created_at']);
return [$note->id,nl2br($note->description ."\n\r\n\rBy ".$note->admin->name ." @ ".date("d/m/Y h:i A",strtotime($note->created_at)))];
});
// dd($notes->flatten()->toArray());
// Otherwise it is displayed as editable
if(count($notes)>0){ //Show Icon, and show Notes in model popup if count greater than 0
return $column->modal('Latest Notes', function ($column) use($notes) {
return new Table(['ID', 'Description'], $notes->toArray(),['table-striped']);
//return new Box('No Information', 'There is no note to show');
});
});`
The text was updated successfully, but these errors were encountered: