I'm using Datatables on my Laravel project to show stock of products, but when I tried to sort it, it's error
This is my script in view
@section('script')
<script type="text/javascript">
$(function () {
var oTable = $('#stock-table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ url("stock-data") }}'
},columns: [
{data: 'updated_at', name: 'updated_at'},
{data: 'product_name', name: 'product_name'},
{data: 'unit_stock', name: 'unit_stock'},
{data: 'status', name: 'status'},
],
});
});
</script>
@endsection
And this is my controller
public function stock()
{
return view('stock-report');
}
public function stockData()
{
$stock = Products::all();
return Datatables::of($stock)
// ->orderColumn('unit_stock $1')
->addColumn('status', function ($stock) {
if ($stok->unit_stock == 0)
return '<span class="label label-danger">EMPTY</span>';
else
return '<span class="label label-success">NOT EMPTY</span>';
})
->make(true);
}
It's error when I add ->orderColumn('unit_stock $1')
, is there any solution, big thanks