How to format numbers in a YUI 3.5 Datatable.
datatable.js
[crayon language="javascript"]
YUI().use(‘datatable’, ‘datatype-number’, function (Y) {
var data = [
{ id: "353", name: "Shanghai", country: "China", population: 17836133,
details: "details" },
{ id: "347", name: "Instanbul", country: "Turkey", population: "13483052" },
{ id: "456", name: "Karachi", country: "Pakistan", population: "13052000" },
{ id: "2344", name: "Cambridge", country: "UK", population: "108863" }
];
function formatNumber(cell) {
valueAsNumber = Y.DataType.Number.parse(cell.value);
return Y.DataType.Number.format(valueAsNumber, {
thousandsSeparator: “,”
});
}
var table = new Y.DataTable({
data: data,
columns: [
{ key: "id", label: "Id", className: "number" },
{ key: "name", label: "City Name" },
{ key: "country", label: "Country" },
{ key: "population", label: "Population", formatter: formatNumber, className: "number" },
{ key: "details", label: " ", allowHTML: true } ],
caption: “World’s largest cities proper”
});
table.render(“#cities”);
});
[/crayon]
Recent Comments