Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .dataTables() jquery plugin question. Unformatted column needs formatted to currency.

    Ok, so I have a problem with a report I am working on using the dataTables jquery plugin. I am building the report with php and javascript, and the data I am using is coming from an associative array. each array in the associative array contains five pieces of info, the last two are numeric and looping through the associative array, nesting a loop through each array within it, I am populating the table. So what I end up with is a table with five columns, the first three of which are text, and the last two are numbers. I want to be able to format just the last two columns for currency. I don't want to format the data within the array before it is populated in the chart, because dataTables has sorting features that would be compromised. I have read the dataTables API, but it hasn't helped. If anyone has any ideas or experience with this issue, please help!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,462
    Thanks
    23
    Thanked 634 Times in 633 Posts
    I don't want to format the data within the array before it is populated in the chart, ....
    When you take info from a database you put it into a variable. So we don't change the array, we will change the variable.

    ....because dataTables has sorting features that would be compromised.
    This part is not true. Looking at the source code of DataTables | Table plug-in for jQuery you will see that the far right column has dollar signs and commas in it. dataTables must be able to handle that cause it does right on that page. Please read instructions for this again.

    What is missing is What currency are you using? Dollars, pounds, etc.. Do you want commas or periods to group the amount? Do you have decimal values or is every thing round to the nearest whole number?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 Posts
    man, that datatables site is a mess, but i found what you need: rowCallback
    that lets you use a template or just code to turn the primitive data value into an html string that tucks inside the corresponding TD.

    edit: you might actually want http://datatables.net/reference/option/createdRow one of those will let you intercept the view without transforming the data.
    Last edited by rnd me; 08-14-2014 at 10:08 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •