简体   繁体   English

R 中带有 DT 数据表的圆形边框

[英]Round borders with DT datatables in R

I would like round borders on my DT table.我想要我的 DT 表上有圆形边框。 Unfortunately my JS skills are very limited (or even inexistent) thus I would be very happy if somebody could help me to figure out how to implement round borders on a DT table in R.不幸的是,我的 JS 技能非常有限(甚至不存在),因此如果有人可以帮助我弄清楚如何在 R 中的 DT 表上实现圆形边框,我将非常高兴。

This is my code so far:到目前为止,这是我的代码:

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      paste0(
        "$(this.api().table().header()).css({
          'background-color': 'black',
          'color': 'white',
          'border-top-left-radius': '4px',
          'border-top-right-radius': '4px'
          });"
      ),
      "}"
    )
  )
)

The last part border-top-left-radius does not work but something like this would be the solution.最后一部分border-top-left-radius不起作用,但类似这样的解决方案。 I think this answer has the solution in pure JS but I need somebody to help me to implement this snippet in my R code.我认为这个答案有纯 JS 的解决方案,但我需要有人帮助我在我的 R 代码中实现这个片段。

Here is a screenshot from my code.这是我的代码的屏幕截图。 Now I would like to have the top left and right border with a radius.现在我想让左上角和右上角的边框有一个半径。 As you can see the border is 90 degrees at the moment.如您所见,此时边界为 90 度。

仍然有尖锐的边界

You have to use overflow: hidden .你必须使用overflow: hidden

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      paste0(
        "$(this.api().table().header()).css({
          'background-color': 'black',
          'color': 'white',
          'border-top-left-radius': '4px',
          'border-top-right-radius': '4px', 
          'overflow': 'hidden'
          });"
      ),
      "}"
    )
  )
)

The following code does the trick!下面的代码可以解决问题! Got the solution from the following link from datatables forum.从数据表论坛的以下链接获得解决方案。

DT::datatable(
  data = iris,
  options = list(
    initComplete = DT::JS(
      "function(settings, json) {",
      "$('th').css({'background-color': 'black'});",
      "$('th').css({'color': 'white'});",
      "$('th:first-child').css({'border-top-left-radius': '15px'});",
      "$('th:last-child').css({'border-top-right-radius': '15px'});",
      "}"
    )
  )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM