cancel
Showing results for 
Search instead for 
Did you mean: 

Change row color at runtime

Former Member
0 Kudos

Hello,

We have a requirement to change a row color dynamically at runtime depending on some condition.

Does anybody know how to do it without setting color context?

Regards,

Santosh

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Santosh,

you can make it possible through javascripting also. While you are loading the applet, you can use the applet creation event to control the color of Grid.

name of the event - CreationEvent

In CreationEvent, you can use javascripting to control the background color of the rows.

exp -

function controlBackGroundRowColor()

{

// controlling the background row color

var color = "#ACDCCA"; // you can set your required color here

if(//required conditions goes here ...)

{

for (int iCol = 0; iCol < document.test_applet.getDisplayObject().getColumnCount();iCol++)

{

document.test_applet.getDisplayObject().setCellBackgroundColor(rownumber,iCol,color);

}

}

}

<applet name="test_applet" width="200" height="200" code="iGrid" -


MAYSCRIPT>

<param name="Query Template" value = "/chv/queryobj">

<param name="Display Template" value = "/chv/dispobj">

<param name="creationEvnent" value = "controlBackGroundRowColor">

Hope that it solves your issue...

Thanks,

Amit

Former Member
0 Kudos

Santosh,

If I understand you correctly, you want to change a rows color at runtime, but not based on the row contents displayed in the grid, at least not any static contents.

I know you explicitly mentioned you don't want to use color contexting, however. At runtime you can update the match values and colors to perform this task.

As long as your grid contains some column with a value that you can trigger off of (even if it is hidden), 'Dynamic Backround' and 'Sting' Match selected.

For the purpose of demonstration lets assume the following:

-You had a column named 'ORDER_ID' (hidden or not, doesn't matter), and it appears in the color context table

-Some event triggers 'f_SomeEvent()' that initiates the change in color

-You want to highlight the row red, your normal backround is black


//Global Variables
var gsMatchColors = "#FF0000,#000000";   //Red, Black
var gsMatchValues= "-,*"                             // '-' is placeholder for Order ID, '*' is wildcard for default backround color 
var gnOrder_ID = 0;

//When page loads
function f_OnLoad() {
   //Set Match Colors
   document.agMyGrid.getGridObject().setMatchColors(gsMatchColors);
   //Set Match Values
   document.agMyGrid.getGridObject().setMatchValues(gsMatchValues);
   //Update Grid
   document.agMyGrid.updateGrid(true);
}

//event fired by whatever is mandating the row color change
function f_SomeEvent() {
   gnOrder_ID = (Order ID from somewhere);
   f_HighlightRow(gnOrderID);
}

function f_HighlightRow(OrderID) {
   gsMatchValues = OrderID + ",*" ;      // New match value sting will be like "12345,*"
   document.agMyGrid.getGridObject().setMatchValues(gsMatchValues);
   document.agKPI1.updateGrid(true);  //Row with Order ID 12345 will now have a red background others will be black
} 

Hope this helps.

Rod Hoffman