Auto format Hyperlinks in cells

Auto format Hyperlinks in cells

AryAry Posts: 1Questions: 1Answers: 0

Hey Forum,

i am using the TablePress Plugin on a WordPress Installation.
I set up some tables where the last cell in every row (4 columns) contains 2 links (mail & www)

have a look at the setup here: http://dr-scheuernstuhl.de/therapeutinnen/

Right now I have to enter <a href="mailto:mail@mail.com?">E-Mail</a> <a href="http://website.com/target=_blank">Website</a> into all of the cells, which is quite inconvenient.

Is there a way to automatically detect hyperlinks so i can just enter "mail@mail.com" and "www.website.com"?

I'm new to DataTables and have very little knowledge of jquery, unfortunately...

thx in advance,
ary

Answers

  • NineForty5NineForty5 Posts: 9Questions: 0Answers: 2

    You can concatenate the field value with the link when you initialize the table using columns.render:

    {
      'render': function(data, type, full, meta) {
       return '<a href="mailto:' + full.email + '?">E-Mail</a>';
      }
    }
    

    If you want email and website in one column just render them both:

    {
      'render': function(data, type, full, meta) {
        return '<a href="mailto:' + full.email + '?">E-Mail</a><br /><a href="http://' + full.website + '"target=_blank">Website</a>';
         }
    }
    

    You can see an example here

This discussion has been closed.