How can I remove hyperlink on DT's filter for a Shiny app

Hello Shiny Developers,

I want to select players on Datatable by using filter . When you transform your column as factor type, Datatable gives you a pop-up for filtering. It works fine but I have a hyperlink with player names. That's why, I can't only see player name while I filtering. How can I remove URL info for filtering.

Thanks!

Please take a look at the proposed solution on this stackoverflow post: How to filter columns containing hyperlinks in r DT - Stack Overflow

Also pasting below in case the link breaks

library(DT)

render <- c(
  "function(data, type, row){",
  "  if(type === 'display'){",
  "    var a = '<a href=\"' + row[3] + '\">' + data + '</a>';",
  "    return a;",
  "  } else {",
  "    return data;",
  "  }",
  "}"
)

df <- data.frame(
  Val = c("A", "B"), 
  url = c("google", "stackoverflow"),
  href = c("https://www.google.com", "https://www.stackoverflow.com")
)
datatable(df, escape = FALSE, filter = list(position = "top"), 
          options = list(
            columnDefs = list(
              list(targets = 2, render = JS(render)),
              list(targets = 3, visible = FALSE)
            )
          )
)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.