The link in my data only shows up as text, how do I make a working link in a datatable?

What I’m trying to do:
Sorry, newbie here. I have a database field that I access through Uplink that is is stored as “/foo/bar/filename.html” I add on the full path to make it a fully qualified URL before I return it to Anvil, so it’s "http://website.com/foo/bar/filename.html."

I want it to display as a clickable link in the datatable.

What I’ve tried and what’s not working:
I’ve tried returning full html, like < a href=‘http://website.com/foo/bar/filename.html’>Link (I left a space in the tag so it would display here) but it just displays as text.

I assume you’re blocking html as some sort of security measure, but how do I format links so they work on Anvil pages?

If you’re displaying the link field as a field in a data grid, then drop a Link component onto that field in the data row template and set the data binding for the url property of the component. That’ll give you a clickable link.

Appreciate the reply, but where do I find the link component to drop it in? I don’t see it in the toolbox.

I see in the documentation how to add it through code, but that doesn’t seem to be working.

It’s the fourth component in the toolbox, the Ab with the blue underline.

Thanks very much, I overlooked it. But how do I get it to show up in my data table. I think I’ve tried every combination of things and either it shows up properly as a link but outside the table, or it just chokes with Bad Input if I try any number of configurations, or it just says “Anvil Link Object.”

Some of the the things I tried:

c = Link(text="I'm learning Anvil",
         url="https://nodejs.org")
    set = [{'submission': 'This is a submission!','date':'This is a date!','link': c}]
    self.repeating_panel_1.items = set

or

  c = "I'm learning Anvil."
    set = [{'submission': 'This is a submission!','date':'This is a date!','link': self.link_1.text=c}]
    self.repeating_panel_1.items = set

Sorry, but my frustration level with this platform is pretty high right now, so maybe I’ll step away for a bit. Or just go back to learning a more standard Python/JS stack.

Hey @dave1

Sorry you’re frustrated.

You’re pretty close though I believe.

When you set a repeating panel’s items it takes a list of dictionaries. Each key in the dicts have to be “bound” to properties of the components in the repeating panel’s template.

You can set this so called “data binding” right in the designer (GUI).

You can also do this via code in the init of the template using self.item.

You do not place the component objects themselves in the repeating panel’s items from what I remember.

The clearest way of learning is to choose any tutorial that involves a repeating panel and check out how it’s all connected. The docs on data binding and repeating panels should help as well.

Folks here are happy to help but I can’t get to a computer tonight (I’m a volunteer here).

Generally, Anvil is VERY straightforward once some initial ideas are understood but it can take some practice that’s for sure!

Here is some documentation that might help

Anvil Docs | RepeatingPanels

It’s always good to share a clone link that way others can make changes and ping it back to you. Almost like a code review :wink:

1 Like