Reputation: 403
This is how i fill my column using a normal html table which works fine
<td>
<span class="status">
@if ($try->status == 0)
<span style="font-size:15px" class="label label-success">Fresh</span>
@elseif ($try->status == 1)
<span style="font-size:15px" class="label label-danger">Stale</span>
@else
<span style="font-size:15px" class="label label-warning">Docked</span>
@endif
</span>
</td>
but now, i want to use a datatables for this and this is how i am doing it but it doesn't work. The column only appears blank although the response is returned from the database.
->addColumn('customer', function ($category) {
return '<p>'.$category->customers->name.'</p>';
->addColumn('status', function ($category) {
'<p>
@if ($category->status == 0)
<span style="font-size:15px" class="label label-
success">Fresh</span>
@elseif ($category->status == 1)
<span style="font-size:15px" class="label label-
danger">Stale</span>
@else
<span style="font-size:15px" class="label label-
warning">Docked</span>
<p>';
})->make(true);
PS: Customer's name appears in the customer
column in the datatables but for status
column, it is empty. Why is this happening with datatables? Could it be my syntax?
Upvotes: 1
Views: 254
Reputation: 312
You need to add return statement on status. and i have updated status code block bit clear.
->addColumn('customer', function ($category) {
return '<p>'.$category->customers->name.'</p>';
}
->addColumn('status', function ($category) {
$status = '<p>';
if ($category->status == 0) {
$status .= '<span style="font-size:15px" class="label label-success">Fresh</span>';
}
elseif ($category->status == 1) {
$status .= '<span style="font-size:15px" class="label label-danger">Stale</span>';
}
else {
$status .= '<span style="font-size:15px" class="label label-warning">Docked</span>';
}
$status .= '</p>';
return $status;
})
->make(true);
Upvotes: 4