Number alignment and display numbers with commas in the standard datagrid

Many of the newer visualization have a Format dropdown that allows you to decide how to display data in various formats. But with the default datagrid, there's not an option in the interface to do it.

A common request is to right justify numeric data in the grid and also to display commas in large number. By default, the data grid will display 1000 and with the code below you can change to to reflect 1,000 as an example.

To implement this, on the server edit the c:\program files(x86)\yurbi\frontend\assets\js\lib\custom.js file.

In the doCustom function add the following code:

cellsrenderer = function(row, columnfield, value, defaulthtml, columnproperties) {
if (columnproperties.columntype == "num" | columnproperties.columntype == "per" | columnproperties.columntype == "cur" | columnproperties.columntype == "dat") {
defaulthtml = defaulthtml.replace("float: null", "float: right;");

} else {
defaulthtml = defaulthtml.replace("float: null", "float: left");
}
if (columnproperties.columntype == "num") {
if (value.toString().indexOf('.') !== -1) {
var tempvalue = parseFloat(value); //if you want decimal places change toFixed(0) to toFixed(n) wehre n is number of decimal places
var strtemp = tempvalue.toLocaleString(undefined, { minimumFractionDigits: 2 });
strtemp = strtemp.toLocaleString();
defaulthtml = defaulthtml.replace(value, strtemp);
} else {
var tempvalue = parseFloat(Math.round(value * 100) / 100).toFixed(0); //if you want decimal places change toFixed(0) to toFixed(n) wehre n is number of decimal places
var strtemp = tempvalue.toLocaleString();
strtemp = strtemp.toLocaleString();
var parts = (''+strtemp).split("."), s = parts[0], i = L = s.length, o = '', c;
while(i--){ o = (i==0 ? '' : ((L-i)%3 ? '' : ',')) + s.charAt(i) + o }
strtemp = o + (parts[1] ? '.' + parts[1] : '');
defaulthtml = defaulthtml.replace(value, strtemp);
}


return defaulthtml;
} else {
return defaulthtml;
}
};

To see the update, be sure to clear your browser cache.