Can anybody tell how to change the color of listview through code.
Like this?
https://docs.suitecrm.com/blog/listview-conditional-formatting/
That one is to apply a different colour to different values, according to some condition in the record.
Or do you just want to change the general styles for List views? In that ase maybe this will help (but you will have to find your way through the CSS)
Hello
I try to highlight case status. I followed this method : https://docs.suitecrm.com/blog/listview-conditional-formatting/ but it doesn’t work.
Do you have any idea what is wrong ? I don’t have error, but my div is not display.
In /custom/Extension/modules/Cases/Ext/LogicHooks/ListViewHighlight.php
$hook_array['process_record'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'Highlight Status',
//The PHP file where your class is located.
'custom/modules/Cases/HighlightStatusLogicHook.php',
//The class the method is in.
'HighlightStatus_class',
//The method to call.
'HighlightStatus_method'
);
In /custom/modules/Cases/HighlightStatusLogicHook.php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class HighlightStatus_class
{
// Ajoute une class css autout du statut
function HighlightStatus_method($bean, $event, $arguments)
{
$colour = substr(md5($bean->status),0,6);
$bean->status = "<div class='status_$colour'>".$bean->status."</div>";
}
}
You are not adding the CSS color properly. CSS goes inside “style”. You are adding a random class that has not been declared anywhere.
Follow the sample and test again:
$colour = substr(md5($bean->industry),0,6);
$bean->industry = "<div style='border: solid 5px #$colour;'>".$bean->industry."
I want to add a css class to manage them in my css file, not a style in the html page.
The problem is not there, the <div…> is not display in the source code (neither with style or class)
Check if your logic hook is getting picked up in the QR&R, it should appear in a file somewhere under custom/modules/Ext
Then check if it is getting called when you expect it to. Make the first statement in your logic hook log something as FATAL in suitecrm.log and then check if it’s there.
Thank you, it was only that ! Just click on Quick Repair and my logic_hook appear !
I have another question : do you know how I can display the Status translation ?
for exemple $bean->status display “Closed_Closed” , and I’d like to display the current language translation
If finally found for the translation. Here the final code for /custom/modules/Cases/HighlightStatusLogicHook.php
class HighlightStatusLogicHook{
public function highlightStatus(SugarBean $bean, $event, $arguments){
global $app_list_strings;
$appListLabel = $app_list_strings['case_status_dom'];
$colour = str_replace(" ", "_",$bean->status);
$bean->status = "<div class='status_$colour'>".$appListLabel[$bean->status]."</div>";
}
}
I open this old post
if I want to simply change the color of the text of a state, can someone explain to me how to do it?
or rather the wording to be applied to the css
I can get the random underline, but I can’t get the color change just for a state
thanks
You need to add a Process hook to the Module and write the code as shared by @metfab.
Here is what i got for my dropdowns.
78/5000
ok, but if I want to assign 1 color
example: only the new state turns red?
no help?
I tried that too but it doesn’t work
<?php
class HighlightStatusLogicHook{
public function highlightStatus(SugarBean $bean, $event, $arguments){
$colour = substr(md5($bean->Converted),0,6);
$bean->Converted = "<div style='border: solid 5px #$colour;'>".$bean->Converted."</div>";
$bean->Converted = "<div style='color: yellow;'>" . $bean->Converted. "</div>";
}
}
You need an “if” for that. Are you a developer?
It’s just a matter of checking if the Bean’s status is “new” and only applying the colour in that case. Also, you don’t need to use that “substr(md5($bean->Converted),0,6)” expression which just picks a (kind-of-)random colour. You just specify “red” or whatever.
thanks pgr
but if I want to color the whole line?
thanks
Luca
I don’t think that is possible from there using just HTML.
It might be possible if you override the view class further up, or if you use some Javacript trick to manipulate the DOM. But I don’t know of a specific way that I can teach you. sorry.