Commas and $ in datatable columns

Commas and $ in datatable columns

MaddyMaddy Posts: 24Questions: 0Answers: 0
edited November 2012 in General
Hi,

I have a datatable with 4 columns that hold currency. Currently I'm treating them as normal columns and manually appending '$' to each value. Now I need to format the column to have commas as well. Is there any plug-in to do this? I also want to remove the manual addition of '$' value. I checked few sites, but I really didn't understand how they work. Thanks a lot for help.
-Maddy

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Maddy,

    It sounds like this plug-in might be the best option for you: http://datatables.net/plug-ins/sorting#formatted_numbers . It simply strips non-numeric data from the source and then sorts what remains numerically.

    Allan
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    I use the following js library for accounting fields.
    http://josscrowcroft.github.com/accounting.js/

    Hope this might help you
  • MaddyMaddy Posts: 24Questions: 0Answers: 0
    Thanks a lot for the responses. I added the formatting at the source itself (in PHP). Here's the function I used -

    setlocale(LC_MONETARY, 'en_US.UTF-8'); at the beginning of the php.

    money_format('%(#10n', $cost)
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Well it depends on what one wants in the project. Personally I would prefer to format the fields only during display. If you do it in PHP, sometimes you might have to strip down all these extras before calculations are done.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Agreed - formatting upon display ( `mRender` for type `display` for example). See: http://datatables.net/blog/Orthogonal_data (mainly talks about mData but mRender is similar).

    Allan
This discussion has been closed.