简体   繁体   English

将自定义类标签添加到数据表行

[英]Add custom class label to datatable row

Is there a possibility to add a costum class label to a data.table row?是否有可能将服装类标签添加到 data.table 行?

I formated my DT row using formatStyle to a yellow background in case a certain condition is fullfilled.我使用 formatStyle 将我的 DT 行格式化为黄色背景,以防满足某个条件。

DT::formatStyle(1, target = "row", backgroundColor = DT::styleEqual(trans_age(), c("yellow"))) %>%

However, the color is not shown when I want to print the table using the print function from my web-browser.但是,当我想使用 Web 浏览器中的打印功能打印表格时,没有显示颜色。 Therefore, my idea is to add a class label to the specific, and to set the colour for the print via a costum css using @media print.因此,我的想法是为特定添加一个类标签,并使用@media 打印通过costum css 设置打印的颜色。

Kind regards, Silke亲切的问候, 西尔克

With the createdRow option:使用createdRow选项:

library(DT)

dat <- iris[1:3,]

js <- JS(
  "function( row, data, dataIndex ) {",
  "  if(dataIndex === 2) {",
  "    $(row).addClass('myclass');",
  "  }",
  "}"
)

datatable(
  dat, 
  options = list(
    createdRow = js
  )
)

This add the class myclass to the third row, since indexing starts at 0 in JavaScript.这将类myclass添加到第三行,因为在 JavaScript 中索引从 0 开始。

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

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