简体   繁体   English

在闪亮的R中的DT中设置扩展行按钮的样式

[英]Styling the expand row button in DT in shiny R

I'm trying to style the expand rows button available in DT. 我正在尝试设置DT中可用的扩展行按钮的样式。 The styling is available here . 样式在这里可用。 The code I'm using for creating the datatable is- 我用于创建数据表的代码是-

library(DT)
datatable(
  cbind(' ' = '⊕', mtcars), escape = -2,
  options = list(
    columnDefs = list(
      list(visible = FALSE, targets = c(0, 2, 3)),
      list(orderable = FALSE, className = 'details-control', targets = 1)
    )
  ),
  callback = JS("
  table.column(1).nodes().to$().css({cursor: 'pointer'});
  var format = function(d) {
    return '<div style=\"background-color:#eee; padding: .5em;\"> Model: ' +
            d[0] + ', mpg: ' + d[2] + ', cyl: ' + d[3] + '</div>';
  };
  table.on('click', 'td.details-control', function() {
    var td = $(this), row = table.row(td.closest('tr'));
    if (row.child.isShown()) {
      row.child.hide();
      td.html('&oplus;');
    } else {
      row.child(format(row.data())).show();
      td.html('&CircleMinus;');
    }
  });"
))*

I'm not well versed with JS so I'm lost where to start off. 我不太精通JS,所以迷路了。 I've tried using the JS and CSS files from the link but haven't been able to make any progress. 我尝试使用链接中的JS和CSS文件,但无法取得任何进展。 Any leads appreciated, thanks! 任何线索表示赞赏,谢谢!

This works like this if you open the table in the browser (this doesn't work in the RStudio viewer). 如果您在浏览器中打开表,则它的工作方式如下(在RStudio查看器中不起作用)。 But I suspect there's an easier solution... Moreover this solution relies on images hosted on Github, that's not very cool... 但我怀疑有一个更简单的解决方案...而且此解决方案依赖于托管在Github上的图像,这不是很酷...

library(DT)
datatable(
  cbind(' ' = '<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_open.png\"/>', 
        mtcars), escape = -2,
  options = list(
    columnDefs = list(
      list(visible = FALSE, targets = c(0, 2, 3)),
      list(orderable = FALSE, className = 'details-control', targets = 1)
    )
  ),
  callback = JS("
                table.column(1).nodes().to$().css({cursor: 'pointer'});
                var format = function(d) {
                return '<div style=\"background-color:#eee; padding: .5em;\"> Model: ' +
                d[0] + ', mpg: ' + d[2] + ', cyl: ' + d[3] + '</div>';
                };
                table.on('click', 'td.details-control', function() {
                var td = $(this), row = table.row(td.closest('tr'));
                if (row.child.isShown()) {
                row.child.hide();
                td.html('<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_open.png\"/>');
                } else {
                row.child(format(row.data())).show();
                td.html('<img src=\"https://raw.githubusercontent.com/DataTables/DataTables/master/examples/resources/details_close.png\"/>');
                }
                });"
))

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

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