How to post-process column values in jQuery DataTables

 var table = $('#data-table').DataTable(
                    ajax: {
                        type: 'GET',
                        url: '/temperature'

                    bFilter: false,
                    "bLengthChange": false,
                    aaSorting: [],
                    columns: [
                        {data: "t"},
                        {data: "c"}


Open in new window

I have the above code to consume some JSON data to populate a table using DataTables ( The JSON format is like below:
{data: [{t:1459192455326, c:2},{t: 1459192455326, c:3}]}

Open in new window


So how can I do some post processing of the returned JSON (convert the timestamp to human readable form) in order to render the table?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
If you have the chance, do the processing on the server-side - i.e. in your temperature script and then return the data as you need it.
condor888Author Commented:
But the thing is that the client's browser has a better idea of the timezone of the client, isn't?
Chris StanyonWebDevCommented:
Ah Ok.  You could always pass the client's timezone into the ajax request
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

condor888Author Commented:
That's a good idea.
Steve BinkCommented:
Sending the timezone in the request is a good idea...your server can handle the conversions in a more consistent way.

That said, you do have post-processing options in DataTables.  See the list of events you can hook into.  You're probably looking for xhr.dt or processing.dt.
condor888Author Commented:
Another question, if i18n is taken into consideration, should we do it on server side or client side?
Steve BinkCommented:
I18n functionality in DataTables consists of setting a language object with the appropriate text strings.  It is more like token replacement rather than true internationalisation.  See what the manual says about I18n.  You have the choice of setting the strings locally, or storing sets of string on the server and having DT load them as needed.  I prefer the second method.
zephyr_hex (Megan)DeveloperCommented:
You can use column rendering to format the date before displaying in the datatable.

Here is the render function definition.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
condor888Author Commented:
I think zephyr_hex's answer is the best. But thanks others for the great input!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.