laravel-splade
laravel-splade copied to clipboard
allow table column classes to be callable
I have tables with columns that I need to change the color based on what the data contains. For instance when displaying 'Approved' I want to make it green. If it's 'Cancelled' I want to make it red. This pull request allows the classes attribute to be a callable function and allows customizing the class based on the data in the column.
Hello James,
This is exactly what I need for a project (displaying 'Approved' I want to make it green. If it's 'Cancelled' I want to make it red). Do you have an example of how I implement it with your changes?
I would be very happy to receive an answer.
Greetings Sebastian
@CoolCookie with this pull request you can do
->column('status', label: 'Status', classes: function ($value, $item) {
if ($value === 'Approved') {
return 'text-green';
}
if ($value === 'Cancelled') {
return 'text-red';
}
})
Since I submitted this request. I've learned of another way to do this with x-splade-cell. Notice the 'status' attribute for x-splade-cell, it's the column key.
<x-splade-table :for="$table">
<x-splade-cell status>
@if ($item->status === 'Approved')
<div class="text-green">Approved</div>
@endif
@if ($item->status === 'Cancelled')
<div class="text-red">Cancelled</div>
@endif
</x-splade-cell>
</x-splade-table>
Hello James,
this is great and helps me a lot with my project. Thank you very much!
Greetings Sebastian