Hyperlink

Hyperlink

VanqVanq Posts: 10Questions: 3Answers: 0

Link to test case: http://live.datatables.net/muyemace/188/edit

Description of problem: Is there a way to show the data in a column as hyperlinks? I want the "google.com" in my column Hyperlink to be clickable and direct me to that URL.

This question has accepted answers - jump to:

Answers

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    Hi
    Perhaps try

              <tr>
                <td>Garrett Winters</td>
                <td><a href="http://www.google.com">google.com</a></td>
                <td>Edinburgh</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$5,300</td>
              </tr>
    
  • VanqVanq Posts: 10Questions: 3Answers: 0

    @Lapointe That works fine, it's just that I get my data from a database and don't have hardcoded data in my rows. (I should have specified that).
    I am working with a SQLite database and get my data from there and with a for loop I get each row. Is there a way to set a column data type to "url/hyperlink"?

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736
    Answer ✓

    Use columns.render. The docs show an example.

    Kevin

  • VanqVanq Posts: 10Questions: 3Answers: 0
    edited January 2022

    @kthorngren Thanks, that works really well.
    With

    {
          "targets": 10,
          "data": "download_link",
           "render": function (data, type, row, meta) {
              return '<a href="' + data + '">' + data + '</a>';
              }
     }
    

    I was able to display the url and not just "Download"

    Another related question: Since I have multiple urls in one cell, I named them.
    For example www.google.com (Google Webpage) www.facebook.com (Facebook Webpage).
    Is there a way to only show the real urls as hyperlinks and the description as normal text? I could always implement a new column and have the names there but that wouldn't be perfect and also even without the names multiple urls are handled as one and don't work properly, is there a way to put multiple urls in one cell and have seperate.

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    www.google.com (Google Webpage) www.facebook.com (Facebook Webpage)

    Is this all one string? If so you will need to parse the string, ie data, to split out the url from the text to display the way you want.

    If you need help please provide a simple running test case that shows an example of your data. This way we can see exactly what you have to offer suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • VanqVanq Posts: 10Questions: 3Answers: 0

    @kthorngren Hey Kevin.

    Test case: http://live.datatables.net/muyemace/193/edit

    It would look something like this if you would look at the "Hyperlink" for Ashton Cox.

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736
    edited January 2022 Answer ✓

    Based on your sample data of google.com (Google Webpage) facebook and google.com you can do something like this example:
    http://live.datatables.net/muyemace/194/edit

    You will notice it doesn't work for fields you didn't update with your example data. You might need to adjust the string parsing to fully match your data and the output you want. Use Stack Overflow for ideas of how to parse your strings.

    Kevin

  • VanqVanq Posts: 10Questions: 3Answers: 0

    @kthorngren Thanks Kevin. That actually works for some of the urls. I have some urls that have an empty space in the url (not web url, path to some folders) :/ which leads to problems I think.
    I will look into parsing the strings.

Sign In or Register to comment.