How can I manipulate how I render data based on the content of a cell?
How can I manipulate how I render data based on the content of a cell?
I am using serverside Datables to much success!
I have ran into a slight issue that I am not sure how to tackle.
In my 'MySQL' database I have a column that will sometimes contain a link and sometimes be null, I am using columns.render to turn this data into a hyperlink within the Jquery datatable. Basically doing something like this
{"data":"url", "render": function(data, type,full,meta){ return '<a href="`+data+`"; target="_blank">Click</a>;
However the null will also be wrapped in the hyperlink, is there a way to have the above code snippet work only when data != null?
Thanks,
Answers
Just so the code doesn't wrap off the screen
{"data":"url", "render": function(data, type,full,meta)
{ return '<a href="`+data+`"; target="_blank">Click</a>;
'RESOLVED:
You can just use
if(data=="null){
return 'whatever'}
else{ return data}
Why not pass the actual HTML and skip the render part all together?
https://jsfiddle.net/glenderson/r1L5nwz2/3/
I put up this fiddle to resolve an issue, but it shows how you can just pass HTML.