Formatting Thousands Separator in Datatable

Software Used:

  • Datatables 1.10.20
  • PHPMyAdmin

Table in PHPMyAdmin

Datatable Display Result:

Wanted:

My Client Wanted to formatting JUMLAH column with thousands separator and right aligned like image below:

Question:

How to do that … ?

Answer:

We can make this code below:

$('#your_tbody_id').DataTable({
  "columnDefs": [
      { targets: 2, "render": $.fn.dataTable.render.number( '.',',', 0 )  },
      { targets: 2, className: "text-right" }
		]
})

Explanation:

  • columnDefs is for column definition
  • targets: 2 is for targetting column with index 2
  • $.fn.dataTable.render.number( ‘.’ , ‘,’ , 0 ) is for formatting number with dot for thousands separator and comma for decimal place and 0 for digit after decimal place
  • className: “text-right” is for right aligned

Thanks for reading

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *