Laravel Datatables多个动作编辑/删除,删除显示为文本

时间:2017-08-06 18:45:11

标签: laravel datatables

我使用datatables yajra / laravel-datatables包。我几乎在那里,但删除按钮显示在文本中。

如何将其显示为按钮或链接?

数据:

build.gradle

JS:

    return Datatables::eloquent(Product::query())
        ->addColumn('action', function($row) {
            return '<a href="/prodicts/'. $row->id .'/edit" class="btn btn-primary">Edit</a>';
        })
        ->addColumn('delete', function ($row) {
            return '<a href="/products/show/1">delete</a>';
        })
        ->make(true);

结果:

enter image description here

2 个答案:

答案 0 :(得分:2)

我找到了解决方案, - &gt; rawColumns:

    return Datatables::eloquent(Product::query())
        ->addColumn('action', function($row) {
            return '<a href="/prodicts/'. $row->id .'/edit" class="btn btn-primary">Edit</a>';
        })
        ->editColumn('delete', function ($row) {
            return '<a href="/products/show/1">delete</a>';
        })
        ->rawColumns(['delete' => 'delete','action' => 'action'])
        ->make(true);

答案 1 :(得分:0)

尝试将class="btn btn-danger"添加到删除锚点。就像你的编辑链接一样。

return Datatables::eloquent(Product::query())
        ->addColumn('action', function($row) {
            return '<a href="/prodicts/'. $row->id .'/edit" class="btn btn-primary">Edit</a>';
        })
        ->addColumn('delete', function ($row) {
            return '<a href="/products/delete/1" class="btn btn-danger">delete</a>';
        })
        ->make(true);