0

How do I append a string to a value in jquery.DataTables? e.g. I want to show 45.6% rather than 45.6. The data is coming from an array of objects where the percentage is as a decimal number rather than a string.

Also, is it possible to wrap a class around a value, (so I can style minus numbers in red for example)?

user3791372
  • 4,445
  • 6
  • 44
  • 78

1 Answers1

0

The docs for datatables isn't as good as it could be. Some digging up unearthed the render property for a column which accepts a function for formatting, so in the dataTable initialisation object :

columns: [
    {title: "Shown %", data: 'percent', render: function(data, type, full, meta) {return data + "%"}},
]

This also answers how to wrap a span around the value for styling!

user3791372
  • 4,445
  • 6
  • 44
  • 78