This article is superseded by Right-aligning numerical fields in views - reworked.

One of the nasty things in Microsoft Dynamics CRM is the fact that numerical fields in views are left-aligned, just like any other column. A typical view looks like this:

This view displays three currency columns, but as the values are left-aligned, it's hard to get an overview about smaller and larger values. And it doesn't look good at all. Wouldn't it be better to have it displayed like this:

While not a perfect layout - the currency symbol is displayed below the column separator - it's much nicer than before and clearly helps to understand the data.

How it works

This is an unsupported customization!

All main views are handled by the hompage.aspx file in the /_root folder. The standard implementation is:

<%@ Page language="c#" Inherits="Microsoft.Crm.Web.EntityHomePage" CodeBehind="Microsoft.Crm.Application.Pages.dll" %>
<%@ Register TagPrefix="mnu" Namespace="Microsoft.Crm.Application.Menus" Assembly="Microsoft.Crm.Application.Components.Application" %>
<%@ Register TagPrefix="cnt" Namespace="Microsoft.Crm.Application.Controls" Assembly="Microsoft.Crm.Application.Components.Application" %>
<%@ Register TagPrefix="loc" Namespace="Microsoft.Crm.Application.Controls.Localization" Assembly="Microsoft.Crm.Application.Components.Application" %>
<%@ Import Namespace="Microsoft.Crm.Application.Pages.Common" %>
<html>
<head>
<cnt:AppHeader runat="server" id="crmHeader"/>

<script language="JavaScript">

function window.onload()
{
HandleBackButtonIssues(_currentTypeCode);
}

</script>

</head>

<body class="stage">

<table class="stdTable" cellpadding="0" cellspacing="0">
<tr height="34">
<td>

<table class="homepage_table" width="100%" cellpadding="0" cellspacing="0">
<col width="60%"><col width="20"><col><col width="40%">
<tr>
<td><cnt:AppQuickFind id="crmQuickFind" runat="server"/></td>
<td align="center"><span class="homepage_span">&nbsp;</span></td>
<td nowrap class="homepage_td"><span style="color:#000000;font-weight:<%= CrmStyles.GetFontResourceAttribute("General.Bold.font_weight") %>;"><loc:Text ResourceId="Web.View_Label_70" runat="server" ID="Text1"/></span></td>
<td><cnt:AppViewSelector runat="server" id="crmViewSelector"/></td>
</tr>
</table>
</td>
</tr>
<tr height="25">
<td><mnu:AppGridMenuBar id="crmMenuBar" runat="server"/></td>
</tr>
<tr>
<td ><cnt:AppGrid runat="server" id="crmGrid" /></td>
</tr>
</table>

</body>
</html>

Columns are simple TD elements and the values are wrapped inside a NOBR tag. Numerical columns have a class name of "num", so a typical numerical value has the following HTML representation:

<td class="xxx" ...><nobr class="num">500,00 €</nobr></td>

All that's needed to right-align numbers in views is adding a piece of JavaScript to the homepage.aspx. It has some consequences though and I'm telling you about it later. But first I want to show you the code:

<%@ Page language="c#" Inherits="Microsoft.Crm.Web.EntityHomePage" CodeBehind="Microsoft.Crm.Application.Pages.dll" %>
<%@ Register TagPrefix="mnu" Namespace="Microsoft.Crm.Application.Menus" Assembly="Microsoft.Crm.Application.Components.Application" %>
<%@ Register TagPrefix="cnt" Namespace="Microsoft.Crm.Application.Controls" Assembly="Microsoft.Crm.Application.Components.Application" %>
<%@ Register TagPrefix="loc" Namespace="Microsoft.Crm.Application.Controls.Localization" Assembly="Microsoft.Crm.Application.Components.Application" %>
<%@ Import Namespace="Microsoft.Crm.Application.Pages.Common" %>
<html>
<head>
<cnt:AppHeader runat="server" id="crmHeader"/>

<script language="JavaScript">

function window.onload()
{
HandleBackButtonIssues(_currentTypeCode);
}

</script>

</head>

<body class="stage">

<table class="stdTable" cellpadding="0" cellspacing="0">
<tr height="34">
<td>

<table class="homepage_table" width="100%" cellpadding="0" cellspacing="0">
<col width="60%"><col width="20"><col><col width="40%">
<tr>
<td><cnt:AppQuickFind id="crmQuickFind" runat="server"/></td>
<td align="center"><span class="homepage_span">&nbsp;</span></td>
<td nowrap class="homepage_td"><span style="color:#000000;font-weight:<%= CrmStyles.GetFontResourceAttribute("General.Bold.font_weight") %>;"><loc:Text ResourceId="Web.View_Label_70" runat="server" ID="Text1"/></span></td>
<td><cnt:AppViewSelector runat="server" id="crmViewSelector"/></td>
</tr>
</table>
</td>
</tr>
<tr height="25">
<td><mnu:AppGridMenuBar id="crmMenuBar" runat="server"/></td>
</tr>
<tr>
<td ><cnt:AppGrid runat="server" id="crmGrid" /></td>
</tr>
</table>

</body>

<script language="JavaScript">
var nobrElements = document.getElementsByTagName("nobr");

if ((nobrElements != null) && (nobrElements.length > 0)) {

   
for(var index in nobrElements) {
       
var nobr = nobrElements[index];

        if ((nobr.className == "num") && (nobr.parentElement != null) && (nobr.parentElement.tagName == "TD")) {
           
nobr.style.textAlign = "right";
        }
    }
}
</script>

</html>

The code is really simple. It is executed after the body has been loaded and scans all NOBR elements for a class name of "num". If a NOBR element is nested inside a TD element, then the runtime style is changed.

That's it. Numbers are now right-aligned. It doesn't work in associated views and it doesn't work in other areas as well, but it does the trick in general.

Disadvantages

The solution is easy and it really helps in our daily work. However, there are two disadvantages. It is an unsupported customization and though it really doesn't do anything bad and it's easy to remove, it does change a CRM source file, leaving your CRM system in an unsupported state.

The second issue is that upcoming updates may not be applied to your system correctly. If you "patch" a CRM file yourself, then a hotfix or update rollup may not update the files you have changed. I noticed this behavior in Visual Studio 2008 update packages as well: files that have been modified (modification date different than creation date) are not replaced during an update.

If you change the homepage.aspx file and you apply an update to your system that includes a newer version of the homepage.aspx file, then it may not be copied to your CRM directory. Keep that in mind before changing anything in your CRM web.

Anyway, I'm very pragmatic and am breaking rules whenever I think that it makes sense. As you know the consequences, it's now up to you to use it or not.