集成 Laravel与 database.net - html 标签在行中可见



我在我的项目中使用此组件:yajra/laravel-datatables

我有控制器:

public function dataTable(Request $request)
{
if ($request->ajax()) {
return Datatables::of($this->model->all())
->addIndexColumn()
->editColumn('enable', function ($row) {
if ($row->enable == 1)
return '<span class="label font-weight-bold label-lg  label-light-success label-inline">aktywny</span>';
else return '<span class="label font-weight-bold label-lg  label-light-danger label-inline">nieaktywny</span>';
})
->editColumn('name', function ($row) {
return Str::limit($row->name, 80, '...');
})
->addColumn('action', function ($row) {
$btn = '<a href="' . route('product.edit', ['id' => $row->id]) . '" class="removeItem"><i class="far fa-edit"></i></a> ';
$btn .= '<a href="' . route('product.destroy', ['id' => $row->id]) . '" class="removeItem"><i class="removeItem far fa-trash-alt"></i></a> ';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
}

和 html:

<table class="table table-bordered data-table    ">
<thead>
<tr class="resources">
<th>ID</th>
<th>Nazwa produktu</th>
<th>Status</th>
<th width="100px" class="text-center">Akcja</th>
</tr>
</thead>
<tbody class="data-table-center">
</tbody>
</table>
</div>
<div class="datatable datatable-bordered datatable-head-custom" id="kt_datatable"></div>


$(function () {
var table = $('.data-table').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('product.dataTable') }}",
language: {
url: "{{ asset('js/lang/Polish.json') }}"
},
iDisplayLength: 50,
render: function (data, type, row) {
return data;
},
columns: [
{data: 'DT_RowIndex', name: 'DT_RowIndex'},
// {data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'enable', name: 'enable'},
{data: 'action', name: 'action', orderable: false, searchable: false},
]
});
});

在状态(启用(列中,我看到的是这个 html 而不是最后一个字符串。好像刀片会严重取代这样的 html。

我的结果:

<span class="label font-weight-bold label-lg label-light-success label-inline">aktywny</span>

观点:https://ibb.co/6tXdH65

我该如何解决它?

只需在函数dataTable操作中添加enable

->rawColumns(['action','enable'])
->make(true);

最新更新