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,715
    Thanks
    25
    Thanked 660 Times in 659 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,461
    Thanks
    11
    Thanked 600 Times in 580 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 11:08 PM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    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
    •