Reputation: 349
I'm trying to display an icon if the value of key_product is equal to 1.
Here is my controller with what I've tried.
return DataTables::of($products)
->editColumn('key_product', function ($row) {
if('key_product' == 1){
'<class="btn btn-info btn-circle"><i class="fa fa-pencil"></i>';
}
return ucfirst($row->key_product);
})
I'm not getting any errors but I still get the database value instead of the icon.
Upvotes: 0
Views: 1126
Reputation: 8252
You are missing a return statement for the html content and the html content will be escaped so you have to add the column to the rawColumns
From the docs:
By default, Laravel DataTables protects us from XSS attack by escaping all our outputs. In cases where you want to render an html content, please use rawColumns api.
Something like this:
return DataTables::of($products)
->editColumn('key_product', function ($row) {
if ($row->key_product == 1) {
return '<button class="btn btn-info btn-circle"><i class="fa fa-pencil"></i></button>';
}
return ucfirst($row->key_product);
})
->rawColumns(['key_product']);
Upvotes: 1