I'm using Laravel 5.4 and Yajra datatable, below is my code working properly but in the 2nd action I've created, The button is not displaying but instead it display the text itself "<a href="/product/'. $row->id .'/create-price" class="btn btn-primary">Add Price</a>" What am I missing ?
public function getProductDatatable()
{
$Product = Product::query();
return Datatables::eloquent($Product)
->addColumn('action', function($row) {
return '<a href="/product/'. $row->id .'/edit" class="btn btn-primary">Edit</a>';
})
->addColumn('add_price', function($row) {
return '<a href="/product/'. $row->id .'/create-price" class="btn btn-primary">Add Price</a>';
})
->make(true);
}
Frontend Part
<script type="text/javascript">
$(function() {
$('#product-table').DataTable({
processing: true,
serverSide: true,
ajax: '{{ url('product/get_product_datatable') }}',
columns : [
{data: 'id', name: 'id'},
{data: 'product_code', name: 'product_code'},
{data: 'action', searchable: false, orderable: false},
{data: 'add_price', searchable: false, orderable: false},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'}
]
});
});
</script>
You need to define rawColumns :
public function getProductDatatable()
{
$Product = Product::query();
return Datatables::eloquent($Product)
->addColumn('action', function($row) {
return '<a href="/product/'. $row->id .'/edit" class="btn btn-primary">Edit</a>';
})
->addColumn('add_price', function($row) {
return '<a href="/product/'. $row->id .'/create-price" class="btn btn-primary">Add Price</a>';
})
->rawColumns(['add_price', 'action'])
->make(true);
}
I found this issue on github, try adding rawColumns
Datatables::eloquent($Product)
->addColumn(..)
->rawColumns(['add_price']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With