rstudio / DT

R Interface to the jQuery Plug-in DataTables
https://rstudio.github.io/DT/
Other
596 stars 182 forks source link

How to use differrent Datatable option in R/Shiny ? #1148

Open yoelii opened 3 weeks ago

yoelii commented 3 weeks ago

Hi, I want to customize my DT by modify several options existing DataTable document. But I don't well understand how I can modify in R/shiny .

For example, I want to change the location of pagination, add icon for copy or print button, ...

On datatable pages, I found this kind of information :

new DataTable('#example', {
    layout: {
        topStart: {
            buttons: [
                {
                    extend: 'copyHtml5',
                    text: '<i class="fa fa-files-o"></i>',
                    titleAttr: 'Copy'
                },
                {
                    extend: 'excelHtml5',
                    text: '<i class="fa fa-file-excel-o"></i>',
                    titleAttr: 'Excel'
                },
                {
                    extend: 'csvHtml5',
                    text: '<i class="fa fa-file-text-o"></i>',
                    titleAttr: 'CSV'
                },
                {
                    extend: 'pdfHtml5',
                    text: '<i class="fa fa-file-pdf-o"></i>',
                    titleAttr: 'PDF'
                }
            ]
        }
    }
});

https://datatables.net/extensions/buttons/examples/styling/icons.html

When I try in R, it's not work.

datatable(
          mydata,
          extensions = 'Buttons',
          options = list(
            dom = '<"top"fpB>t<"bottom"il>',
            buttons = c('copy', 'csv', 'pdf', 'print'),
            searchHighlight = TRUE
          )
        )

I modify, not easily the location of element by dom option by not layout

datatable(
          parameters_ui$results,
          extensions = 'Buttons',
          options = list(
            dom = '<"top"fpB>t<"bottom"il>',
            buttons = c('copy', 'csv', 'pdf', 'print'),
          )
        )
datatable(
          my_data,
          options = list(
               layout = list(topstart = 'paging', bottomEnd = NULL)
          )
        )

Thanks in advance for your help

stla commented 3 weeks ago

The option name is dom. On the datatables.net website, the documentation is given for version 2, while the R package DT uses version 1.

yoelii commented 3 weeks ago

Yes, but It's work well for change location of pagination with modification in CSS style How I can change button by icon for example ?

stla commented 3 weeks ago

Please next time use StackOverflow for such a question. I wrote this question for you and I answered it: https://stackoverflow.com/q/78889329/1100107.

The Github issues are rather used to report some bugs or to request some features.

yoelii commented 3 weeks ago

Thanks you for your answer in StackOverflow. I ask my question in github page because I think to the possibility to use icon extensions from DataTabel ( https://datatables.net/extensions/buttons/examples/styling/icons.html) or default icon for pagination link in zero_configuration (https://datatables.net/examples/basic_init/zero_configuration.html)