Quantcast
Channel: Free community support — DataTables forums
Viewing all articles
Browse latest Browse all 35271

Function expression usage in columns.render

$
0
0

Hello everyone,

New to Datatables and I love it. I had a question.
The way that I controlling datatables initialization for various pages in my code is via server side. from the server I get a fully constructed JSON string options which I pass on the datatables contructor.

For one rendering requirement of a date column I have to use a function expression which is declared elsewhere in my javascript code. as an example, on the page I get following JSON string contructed where 'datatableconvertdate' is actually a function expression. But datatable throws an error when I start adding rows / data ( is in javascript object) via ajax call. the debug is at http://debug.datatables.net/uluvez

{"columns":[{"data":"id"},{"data":"file.fileName"},{"data":"file.orgname"},{"data":"file.fileNamePattern"},{"data":"processStatus"},{"data":"triggerredOn","render":"datatableconvertdate"},{"data":"completedOn","render":"datatableconvertdate"}]}

If I change my above JSON string with following then the code works fine.

{"columns":[{"data":"id"},{"data":"file.fileName"},{"data":"file.orgname"},{"data":"file.fileNamePattern"},{"data":"processStatus"},{"data":"triggerredOn","render":function ( data, type, row, meta ) {if ( type === 'display' || type === 'filter' ) {return (moment(data).format("ddd MM/DD/YYYY (HH:mm)"));}return data;}},{"data":"completedOn","render":function ( data, type, row, meta ) {if ( type === 'display' || type === 'filter' ) {return(moment(data).format("ddd MM/DD/YYYY (HH:mm)"));}return data;}}]};

I do not want javascript code to be sitting on my server code which is why I was looking for using function expressions. is there a way out?


Viewing all articles
Browse latest Browse all 35271

Trending Articles