从Reactable表中删除全选/无复选框

问题描述 投票:0回答:1

我想从可反应表中删除全选/无复选框。 在此图像中,我不希望出现橙色圆圈复选框。 enter image description here

使用 Chrome Inspector,检查此复选框的 css 并设置

display: none;
enter image description here

这将删除整列复选框。我该如何删除这个?

R 脚本

library(reactable)

reactable(iris,
          onClick = "select",
          selection = "multiple") 
css r reactable
1个回答
1
投票

你可以附加一些 javascript 代码并使其在渲染可响应时运行: 即

// Hide  the select all check box
document.querySelector('.rt-select-input[aria-label="Select all rows"]').parentElement.parentElement.style.display = "none";

最终的 R 代码

library(reactable)
library(htmlwidgets)
e<-reactable(iris,
          onClick = "select",
          selection = "multiple")

javascript <- JS('
document.querySelector(\'.rt-select-input[aria-label="Select all rows"]\').parentElement.parentElement.style.display="none";
')



(p <- prependContent(e,onStaticRenderComplete(javascript)))

改进

为了简化流程并专门针对所需的复选框(因为上述方法在处理同一页面中的 2 个表时会不成功),我编写了一个函数来动态地针对所需的复选框:


hide.select.all <- function(x){
  javascript <- JS(paste0('
  let id = null;
  for (const script of document.querySelectorAll("script[data-for]")) {
    if(script.text.includes("', x$x$tag$attribs$dataKey ,'")) {
      id="#" + script.dataset.for;
      break;
    }
  }
  if(id) document.querySelector(id + \' .rt-select-input[aria-label="Select all rows"]\').parentElement.parentElement.style.display="none";
  ')) 
   prependContent(x,onStaticRenderComplete(javascript))
}

hide.select.all(e)
© www.soinside.com 2019 - 2024. All rights reserved.