Avatar of maddisoncr
maddisoncr
 asked on

Datatables jQuery Format Problem

I am using the datatables plug in and i want to show numerical data with 2 decimal places.

I am using similar php scripts that the author uses and as such, i don't to format the data at that stage.. i want to format the data client side

I have found a datatables article : http://datatables.net/forums/discussion/comment/23760 but it uses depreciated methods

I also want to produce my own calculated columns

Thanks
jQuery

Avatar of undefined
Last Comment
plpitcher

8/22/2022 - Mon
maddisoncr

ASKER
Rainer Jeschor

Hi,
depending on your data / html source, the following option should work:
            "aoColumnDefs": [ 
            {
                "mRender": function ( data, type, row ) {

                    return parseFloat(data).toFixed(2);
                },
                "aTargets": [ 6 ]
            }

Open in new window

Just verify the column index - from the attached PDF it looks like column 7 (hence index 6).

Sample:
http://jsfiddle.net/EE_RainerJ/3frAT/

HTH
Rainer
maddisoncr

ASKER
Thank you so much, i really appreciate it

How would i go about looking at calculated columns ?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
maddisoncr

ASKER
thanks again for that, it's working great

in terms of adding commas.. i presume i would still use the plug in as before ?
ASKER CERTIFIED SOLUTION
Rainer Jeschor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
maddisoncr

ASKER
Thanks so much, i'll test that this afternoon :-)
maddisoncr

ASKER
Thanks again.. Brilliant
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
maddisoncr

ASKER
Great help
plpitcher

{
                               "mRender": function (data, type, row) {
                                   return parseFloat('currentBalance').toFixed(2);
                               }
                           },
The above is not working for me.  What do I need to do?  The data type for 'currentBalance' is decimal.