Hello and welcome to our community! Is this your first visit?
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
    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. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,012 Times in 1,009 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.
    Physics is actually atoms trying to understand themselves.

  3. #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 626 Times in 605 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.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


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