my code stock.com

Luke Simcock

change formatting on a grid, add colours, bold, add links
by Luke Simcock

wrap text inside a grid with formatting or make into a URL link etc

Snippet options

Download: Download snippet as change-formatting-on-a-grid-add-colours-bold-add-links.js.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

gridDatasheet.attachEvent("onFormatCellValue", function(pParameters){
	if ((pParameters.fieldName === 'RiskRating') || (pParameters.fieldName === 'EvalRiskRating')) {
		if (pParameters.value !== null) {
			pParameters.value = "<div style='background-color:" + GetColourCode(pParameters.value) + "; font-weight: bold;'>"+pParameters.value+"</div>";
		}
	}
});

// function for Actions
gridActions.attachEvent("onFormatCellValue", function(param){
	if (param.fieldName === 'Status') {
		if (param.value !== null) {
			param.value = "<div style='background-color:" + GetColourCode(param.dataRow.ColourIndex.toString()) + ";'>"+param.value+"</div>";
		}
	}
});


function GetColourCode(vCode) {
	var vColour;

	if (vCode === '1') {
		vColour = "#FF3300"; // red
	} else if (vCode === '2') {
		vColour = "#FFFF00"; // yellow
	} else if (vCode === '3') {
		vColour = "#99CC00"; // green
	} else {
		vColour = ""; // white
	}
	return vColour;
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.