HTML Display Issue When Using Rendering

HTML Display Issue When Using Rendering

hamlet1964hamlet1964 Posts: 43Questions: 8Answers: 1

I have a table displayed in html with numbers such as 10,345.42 and 237.99. I wish to truncate these so they display as 10,345 and 237 (or 238).

In using the "rendering" function [render: $.fn.dataTable.render.number( ',', '.', 0)], the data displays as 10 and 237. The ones, tens and hundreds places are being dropped from numbers >= 1,000.

Code snippet:

    $(document).ready(function() {

var table6 = $('#scats2b').DataTable( {
    dom: "Brt",
    "pageLength": 100,
    ajax: 'php/table.scats2b.php',
    "ordering": true,
    columns: [
        {
            "className": "dt-right", 
            "data": "Year"
        },
        {
            "className": "dt-right",
            "data": "Month"
        },
        {
            "className": "dt-right",
            "data": "Total",
            render: $.fn.dataTable.render.number( ',', '.', 0)
        },
        {
            "className": "dt-right", 
  ......

Any thoughts on how to resolve this display issue?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,230Questions: 1Answers: 10,416 Site admin

    The number renderer expects an unformatted number as its input. How are you currently adding the thousands separator? Either modify that to also do the rounding, or drop it and let the number renderer do all of the formatting.

    Allan

  • hamlet1964hamlet1964 Posts: 43Questions: 8Answers: 1

    Ah, that is the issue. Thanks!!

    So here's the JSON return from php:

    {"data":[{"DT_RowId":"row_ ","Year":"2016","Month":"11","Total":"11,664.95", ....

    The last lines of my php file are:

    ->process( $_POST )
    ->json();

    I can't figure out how to unformat the json data, which is coming from MariaDB (running XAMPP for OS X 7.2.5). Any thoughts???

  • allanallan Posts: 63,230Questions: 1Answers: 10,416 Site admin
    Answer ✓

    What is doing the formatting in the first place? Or is it stored like that in the database as a string?

    Allan

  • hamlet1964hamlet1964 Posts: 43Questions: 8Answers: 1

    Yes, again. It was my table formatting.

    Problem solved!

    thanks!!!

This discussion has been closed.