How to only include a link if the link exists

How to only include a link if the link exists

redroosterdesignredroosterdesign Posts: 15Questions: 2Answers: 0
edited May 2022 in Free community support

https://redroosterdesign.com/ttuhsc-design-library/directory-1-v2.html:
Description of problem: I have figured out how to pull the url from a currently hidden column that is passed to the first name column. The first person in this list does not have the url data, but the hyperlink is showing anyway, it's just an empty url. I would like to figure out how to only show that hyperlink on the first name if the data in the url exists.

I'm using this columnDefs to pull the url:

"targets": [0],
"data": "url",
"render": function(data, type, full, meta){
return '<a href='+full.url+'>'+data+'</a>';

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    Add an if condition:

    if (full.url === '') {
      return '';
    }
    

    Allan

  • redroosterdesignredroosterdesign Posts: 15Questions: 2Answers: 0

    You are a life saver! Worked like a charm. Thank you!

Sign In or Register to comment.