Skip to content
Advertisement

Not able to format DataTables data that is coming from a mysql database using php

I’m using the dataTables plugin to deal with some data. I’m using a mysql database and php. I’m able to display the data in the database, but I’m not able to format it. I have some fields that are dollar amounts, and I’d like to add dollar signs and thousands commas. Can anyone tell me how to do this please? The columns properties in dataTables don’t work for me because the columns are being defined in the php file. The code below works, but I can’t format my currency columns.

HTML:

JavaScript

jQuery:

JavaScript

PHP from getTables.php file.
This is copied from a tutorial. I just plugged in my database details. The code works; I just can’t format my currency columns:

JavaScript

Advertisement

Answer

You can add a callback to do your formatting in either the php or javascript.

Backend solution:

JavaScript

Or you could do your formatting on the front end:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement