Wednesday, June 8, 2011

alternate colors in the main grid of ms crm 4.0

Sometimes the requirement used to come as the records in the main grid to be alternate colors as in normal grid controls.
keep it in mind we are going to alter the aspx page provided by MS CRM :P
To achieve it in CRM just needs some JS code.

1. open the HomePage.aspx from the _root folder
2. append a method onload of the body as <body class="stage" onload="alterGridRecords()">
3. now the function alterGridRecords should be as followed

function alterGridRecords(){
var grid = document.getElementById("gridBodyTable").lastChild; //gridBodyTable is the id, wch will help
for (var i = 0; i < grid.childNodes.length; i++)
{
if ((i % 2) == 0) {
grid.childNodes[i].style.backgroundColor = "#EEEEEE"; //put color as per the user requested
grid.childNodes[i].colourised = true;
}
else {
grid.childNodes[i].style.backgroundColor = "#FFFFFF"; //put color as per the user requested
grid.childNodes[i].colourised = true;
}
}
}

this is so simple

one prob in the above is that you will not be able to make the selected records in diff color.
so just a bit twist
grid.childNodes[i].childNodes[2].style.backgroundColor = "#FFFFFF";
this will make alternate colorsonly the 1st column as its being implemented as only one color in ms crm 2011. :P

No comments:

Post a Comment