jQuery DataTable Number Format of ajax data soure

jQuery DataTable Number Format of ajax data soure

ShujaatShujaat Posts: 3Questions: 1Answers: 0

I have Ajax data source which contains the numbers and strings, the numeric data not in thousand comma separated format. Is the any function or property of datatable that will convert number to thousand comma separated format before binding to datatable? there is "sType" but used for sorting and searching not for displaying data in specific format.

Any Help?

Thanks in advance

Answers

  • vogomatixvogomatix Posts: 38Questions: 3Answers: 7
    edited August 2014

    The default number formatter in Datatables displays values with comma separators

    See formatNumber

  • ShujaatShujaat Posts: 3Questions: 1Answers: 0

    Thanks for the reply, but nothing works for me, by default datatable doesn't show numeric values with thousand comma separation.

    simple js is:

    var dataSet = [ [10000, 10000, 10000, 10000, 10000], [10000, 10000, 10000, 10000, 10000], [10000, 10000, 10000, 10000, 10000] ]; $(document).ready(function () { $('#demo').html('
    '); $('#example').dataTable({ "formatNumber": function ( toFormat ) { return toFormat.toString().replace( /\B(?=(\d{3})+(?!\d))/g, "'" ); }, //"language": { // "decimal": ",", // "thousands": "." //}, "aoColumns": [ { "title": "Engine", "sType": "numeric-comma" }, { "title": "Browser"//, //"sType": "numeric-comma" }, { "title": "Platform"//, //"sType": "numeric-comma" }, { "title": "Version", "class": "center"//, //"sType": "numeric-comma" }, { "title": "Grade", "class": "center"//, //"sType": "numeric-comma" }, ], "aaData": dataSet }); });
This discussion has been closed.