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?

AizandeAizande Posts: 12Questions: 5Answers: 0

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=&quot;_blank&quot;>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

  • AizandeAizande Posts: 12Questions: 5Answers: 0

    Just so the code doesn't wrap off the screen
    {"data":"url", "render": function(data, type,full,meta)
    { return '<a href="`+data+`"; target=&quot;_blank&quot;>Click</a>;'

  • AizandeAizande Posts: 12Questions: 5Answers: 0

    RESOLVED:

    You can just use if(data=="null){ return 'whatever'} else{ return data}

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    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.

This discussion has been closed.