Modifying Column Display Based on Condition in Laravel 9 Controller

QuestionsModifying Column Display Based on Condition in Laravel 9 Controller
Gert Zumtobel asked 1 month ago

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

1 Answers
Abu Ghufran Staff answered 1 month ago

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 "...";
}
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

12 + 5 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?