Hello, I’m working with Laravel 9 and need to modify the display of a column based on its value within the controller. Here’s the basic setup of my column in the grid:
$col = [];
$col['title'] = 'Status'; // caption of column
$col['name'] = 'status_name';
$col['editable'] = true;
$col['width'] = '9';
$col['align'] = "center";
$col['search'] = false;
$cols[] = $col;
Sure, here is your inquiry in English, ready for you to post in a support forum:
Title: Modifying Column Display Based on Condition in Laravel 9 Controller
Hello, I’m working with Laravel 9 and need to modify the display of a column based on its value within the controller. Here’s the basic setup of my column in the grid:
php
$col = [];
$col['title'] = 'Status'; // caption of column
$col['name'] = 'status_name';
$col['editable'] = true;
$col['width'] = '9';
$col['align'] = "center";
$col['search'] = false;
$cols[] = $col;
I want to append specific text to the display value of $col['name']
based on its value. For example, if $col['name']
displays ‘StatusA’, it should instead display ‘StatusA (10)’. If it shows ‘StatusB’, it should display ‘StatusB (20)’. The appended text varies depending on the initial value.
Is it possible to achieve this directly in the Laravel controller? If so, how can I implement this conditionally based on the value of $col['name']
? Any guidance or examples would be greatly appreciated.
Gert
You can try following, and add a controller function with name display_status.
$col["on_data_display"] = array("display_status",$this); public function display_status($data) { $s = $data["status_name"]; if ($s == "StatusA") return "StatusA (10)"; else if ($s == "StatusB") return "StatusA (20)"; else return "..."; }