CRUD: setuplist Row background color #525
-
I have to highlight some rows based on a criterion, for example I would like to change the background color of the records that have the field "active" = false, do I have to use the custom view or is there a faster method? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@pxpm Hi Pedro, have you seen this ? :) |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a workaround if you are still interested, add javascript into your global script file -- app.js and listen ajax complete function in jQuery $(document).ready(() => {
$(document).ajaxComplete(function (event, jqXHR, ajaxOptions) {
const project = new Project();
project.checkRows();
});
}); Make function that will check row, something like this class Project {
checkRows() {
$('[data-mark="true"]').each(function () {
const $this = $(this);
const min = $this.data('min');
const current = $this.data('current');
let elem = $this.closest("tr");
if (min > current && current > 0) {
elem.css('background-color', '#ee8e8e');
elem.addClass("blinking");
} else {
elem.css('background-color', 'initial');
}
});
}
} Add a new file, a custom column for the Laravel Backpack
And add your custom code, in my case is like this CRUD::column('id')
->label("#ID")
->type("row_id"); {{-- regular object attribute --}}
@php
$column['value'] = $column['value'] ?? data_get($entry, $column['name']);
$column['escaped'] = $column['escaped'] ?? true;
$column['limit'] = $column['limit'] ?? 32;
$column['prefix'] = $column['prefix'] ?? '';
$column['suffix'] = $column['suffix'] ?? '';
$column['text'] = $column['default'] ?? '-';
if($column['value'] instanceof \Closure) {
$column['value'] = $column['value']($entry);
}
if(is_array($column['value'])) {
$column['value'] = json_encode($column['value']);
}
if(!empty($column['value'])) {
$column['text'] = $column['prefix'].Str::limit($column['value'], $column['limit'], '…').$column['suffix'];
}
$current= $entry->finalMarkForProject ?? 0;
$min = (float)config("settings.final_mark_for_project", 51);
@endphp
<span data-mark="true" data-min="{{$min}}" data-current="{{$current}}">
@if($column['escaped'])
{{ $column['text'] }}
@else
{!! $column['text'] !!}
@endif
</span> I hope that will help you, |
Beta Was this translation helpful? Give feedback.
-
@arminkardovic Thanks for your share and sorry for delay.. |
Beta Was this translation helpful? Give feedback.
Hi,
I have a workaround if you are still interested,
add javascript into your global script file -- app.js and listen ajax complete function in jQuery
Make function that will check row, something like this