I had the same problem.
Also, I wanted jqGrid
to display my figures with thousand separators and 2 decimal places, but using the default 'number'
formatter caused any nulls (from the database) to get displayed as "0.00
" rather than being left blank.
$("#tblListOfRecords").jqGrid({
...
colModel: [
{ name: "SomeNumber", formatter: 'number', sorttype: "integer", formatoptions: { decimalPlaces: 2 } }
]
...
This wasn't quite what I wanted.
My solution was to write my own formatter:
$("#tblListOfRecords").jqGrid({
...
colModel: [
{ name: "SomeNumber", formatter: formatNumber}
]
});
function formatNumber(cellValue, options, rowdata, action) {
// Convert a jqGrid number string (eg "1234567.89012") into a thousands-formatted string "1,234,567.89" with 2 decimal places
if (cellValue == "")
return "";
if (cellValue == null || cellValue == 'null')
return "";
var number = parseFloat(cellValue).toFixed(2); // Give us our number to 2 decimal places
return number.toLocaleString(); // "toLocaleString" adds commas for thousand-separators.
}
null
andundefined
should be converted automatically fiddle – Clydeclydebank