Changing CELL style based upon value

Discuss MySQL Ajax Table Editor

Changing CELL style based upon value

Postby Wysocki » Tue Mar 29, 2016 5:24 pm

This has been raised in other posts, but without a real answer. I want to style a cell dynamically based upon the value of the cell (or another cell in the row). Typically, solution would look like this:

Add a line like this in the $tableColumns definition:
Code: Select all
'table_fun' => array(&$this,'setColor'),

Then place this function OUTSIDE of the initiateEditor() function:
Code: Select all
   function setColor($col,$val,$row,$instanceName,$rowNum)
   {
       $html = $val;
       if ($val < 0)
       {
           $html = '<div style="background-color:red;">'.$val.'</div>';
       }
       return $html;
   }

Unfortunately, the div only colors the full lineheight of the text. It does not completely fill the cell if the row has been stretched taller because of other data cells. Is there any way to affect the css of the parent <td> or higher?
Wysocki
 
Posts: 15
Joined: Wed Jun 06, 2012 1:30 am

Re: Changing CELL style based upon value

Postby zelia » Mon Feb 05, 2018 5:14 pm

Hello,
Okay, it's been a while since you asked this but since there are no replies and since others might have the same question....

Change this:
$html = '<div style="background-color:red;">'.$val.'</div>';

to this:
$html = '<div style="background-color: red; width: 100%; height: 100%;">'.$val.'</div>';
zelia
 
Posts: 3
Joined: Sun Jan 28, 2018 3:19 pm


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 8 guests

cron