1

I have a list with a hyperlink field. I want to format the link to look like a button. I have tried a gazillion websites, gotten all kinds of CSS, but none of it seems to work.

I've tried two approaches - creating a button and creating an anchor hyperlink. The button type doesn't seem reasonable, as the "action" value set is limited to row list actions (open, edit, delete, etc.)

Here's a sample of what I've tried using an anchor hyperlink:

{
  "elmType": "a",
  "txtContent": "Go to Client Data",
  "style": {
    "text-align": "center",
    "display": "inline-block",
    "padding": "4px 4px 4px 4px"
  },
  "attributes": {
    "class": "sp-field-quickAction",
    "href": "[$ClientSiteURL]",
    "target": "_blank"
  }
}
1

2 Answers 2

0

Please use the below JSON Formatting:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "href": "[$ClientSiteURL]",
    "target": "_blank"
  },
  "children": [
    {
      "elmType": "button",
      "txtContent": "Go to the Client Site URL",
      "style": {
        "background-color": "#E6E6FA",
        "color": "#2F4F4F",
        "width": "100%",
        "font-weight": "bold"
      }
    }
  ]
}

enter image description here

enter image description here

1
  • 1
    What's the difference between JSON code I provided in my answer and your answer (except some extra styling)? Dec 2, 2021 at 14:08
4

Use JSON like below to create hyperlink with button:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "href": "[$ClientSiteURL]",
    "target": "_blank"
  },
  "style": {
    "text-decoration": "none"
  },
  "children": [
    {
      "elmType": "button",
      "txtContent": "Go to Client Data",
      "style": {
        "cursor": "pointer",
        "width": "100%"
      }
    }
  ]
}

Sample output:

enter image description here

Documentation: Use column formatting to customize SharePoint

1
  • I had tried this and it wasn't working - it turns out I had a missing bracket. Thanks for your help and providing me the PROPER coding!!! Dec 2, 2021 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.