Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample 3 - Color added to list item does not work in TOC Main grid #2

Open
sachinbijadi opened this issue Nov 30, 2018 · 3 comments
Open

Comments

@sachinbijadi
Copy link

Html tag with font color added to list item label works only in relationship tab but not main TOC grid:
image
image
image

@AngelaIp
Copy link
Owner

AngelaIp commented Dec 3, 2018

I have to admit that the list coloring sample is interesting proof-of-concept, but not the best way to do coloring. I use this one to color a list in a relationship grid. The list value is set automatically, so users do not see the html code in the dropdown list. It´s the lazy way to do coloring, when you don´t want to change the Method.
For your Make/Buy coloring I would recommend to extend the Method used for coloring the state property. Instead of setting the background-color, you can also change the text color, text font or whatever you like.

@sachinbijadi
Copy link
Author

I tried adding the text color bit to the method. However I think I am making some mistake in the css assignment at the end (myCss) bit, so now i get Make/ BUy coloring but not state coloring. What is the syntax for that last bit to add both state background color and text color for make/buy to the css?
My code here:
'''
// Add Method in ItemType (e.g. Part) -> Server Events -> Event: onAfterGet

for (int i = 0; i < this.getItemCount()-1; i++)
{
string bg_color_state;
string text_color_source;
string myCss = "";

Item thisItem = this.getItemByIndex(i);

string thisStatus = thisItem.getProperty("state","");
string thisSource = thisItem.getProperty("make_buy","");

 // Choose color for 'State'
switch (thisStatus)
{
    case "Preliminary":
    case "In Review":
    case "In Change":
        bg_color_state = "#FFFFBB"; // light yellow
        break;
        
    case "Released":
        bg_color_state = "#90EE90"; // light green
        break;
        
    case "Superseded":
    case "Obsolete" :
        bg_color_state = "#FFBBBB"; // light red
        break;
        
    default:
        bg_color_state = ""; // none
        break;
}

 // Choose text color for 'Make / Buy'
switch (thisSource)
{
    case "Make":
        text_color_source = "red"; 
        break;
        
    case "Buy":
        text_color_source = "black"; 
        break;
        
    default:
        text_color_source = "black"; // if blank
        break;
}

//  set background color
if (bg_color_state != "")
{
     myCss = ".state { background-color: " + bg_color_state + " }"  ;
}
//  set text color
if (text_color_source != "")
{
     myCss = ".make_buy { color: " + text_color_source + " }"  ;
}

thisItem.setProperty("css",myCss);

}
return this;
'''

@AngelaIp
Copy link
Owner

AngelaIp commented Dec 5, 2018

I think your current css code overwrite each other. Haven´t tried your sample but maybe using += instead of = helps?

if (bg_color_state != "")
{
     myCss = ".state { background-color: " + bg_color_state + " }"  ;
}
//  set text color
if (text_color_source != "")
{
     myCss += ".make_buy { color: " + text_color_source + " }"  ;   // <-connect css string
}

Some background information about how the code works at all. What we do is overwriting the property "css" of ItemType Part. It´s a regular property, just like make_buy or item_number. We add one big string with all css information for various properties into this single property.

If you have a static ItemType, were the coloring shall be fixed, I wouldn´t recommend to use this code. Default css coloring can also be done in the ItemType directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants