Hi everyone! I have on my controller this method:
public function index_data()
{
$productos = Product::with('category')
->with('product_canals')->orderBy('name', 'ASC');
return DataTables::eloquent($productos)->addColumn('prices',function (Product $product) {
return $product->product_canals->map(function($product_canal) {
if($product_canal->canal->id == 1)
return $product_canal->price;
})->implode('');
})->make(true);
}
And on the view I have this:
$(function() {
$('#products').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('products_datatable') !!}',
columns: [
{ data: 'name', name: 'products.name' },
{ data: 'category.name', name: 'category.name' },
{ data: 'prices', name: 'prices', render: $.fn.dataTable.render.number( ',', '.', 2, '$ ' ) },
]
});
});
But the result for null value on price column show $ NaN.N
(see attached file)
Can you help me?