New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying Column width #29

Closed
mtseman opened this Issue Mar 23, 2015 · 11 comments

Comments

Projects
None yet
10 participants
@mtseman
Copy link

mtseman commented Mar 23, 2015

I am trying to adjust the column width for given columns. I am not sure what to use as the units on width or how to specify width.

On the DT site, it mentions it accepts any CSS value, I tried '30%',
http://datatables.net/reference/option/columns.width

I have also tried '150px', just a number like 200 (no quotes). Nothing changes the width.

What ever I specify for width displays the same out put.

DeptEditDT <- datatable(
  df, rownames=FALSE,
  extensions = list(Scroller=NULL, TableTools=NULL, FixedColumns=list(leftColumns=2)),
  options = list(
    dom = 'T<"clear">lfrtip',
    columnDefs = list(list(width = '20%', targets = list(2,3,4))),
    deferRender=TRUE,
    scrollX=TRUE,scrollY=400,
    scrollCollapse=TRUE,
    pageLength = 100, lengthMenu = c(10,50,100,200),
    tableTools=list(sSwfPath = copySWF('www'),aButtons=c('copy','csv','print'))
  )
)

In another section of code, I have a simpler DT and also tried to change the width here thinking the list of combined extensions was somehow getting in the way. Whatever I specify for width the column stays the same.

PrgEditDT<-datatable(df, rownames=FALSE, 
                       options = list(dom = 't',
                       columnDefs = list(list(width = '40%', targets = list(2,3,4)))))
@yihui

This comment has been minimized.

Copy link
Member

yihui commented Mar 23, 2015

I just tested your configurations, and I realized you'd have to use autoWidth = TRUE in options to make width work.

In your second example, I guess you cannot make the width of all three columns to be 40%, since 40 * 3 = 120%.

@yihui yihui closed this in a32a539 Mar 23, 2015

@mtseman

This comment has been minimized.

Copy link

mtseman commented Mar 23, 2015

Yep. Works now. Thanks!

@zizaozi

This comment has been minimized.

Copy link

zizaozi commented Jun 16, 2015

I tried to use your code to control the column width. I realized that if leave out the options: scrollX=TRUE,scrollY=400. Then it doesn't work. Don't know why.

@ndimhypervol

This comment has been minimized.

Copy link

ndimhypervol commented Aug 30, 2015

Yep, same for me as @zizaozi (above). Should it be necessary to specify these params too?

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Aug 30, 2015

Same as ??

@kdaily

This comment has been minimized.

Copy link
Contributor

kdaily commented Dec 4, 2015

Same problem - must specify scrollX=TRUE.

@thecharleschin

This comment has been minimized.

Copy link

thecharleschin commented Mar 7, 2017

I just want to add that I've been trying to debug this column width problem for a few days until I stumbled on this thread. Specifying scrollX=TRUE fixed all my issues. Thank you all for the help.

@samuel-bohman

This comment has been minimized.

Copy link

samuel-bohman commented Mar 31, 2017

Same here, adding scrollX = TRUE in the options list solves the problem.

@tsouchlarakis

This comment has been minimized.

Copy link

tsouchlarakis commented May 13, 2017

I don't suppose there is a way to change column widths without specifying scrollX = TRUE? For larger page lengths, this puts the scroller all the way at the bottom. Some users might not even know there is a scroller all the way at the bottom of the table.

@mjlarsen

This comment has been minimized.

Copy link

mjlarsen commented Feb 13, 2018

Is there no way you can avoid scrollX = TRUE to be able to control the width - as tsouchlarakis points out, that for larger page lengths, this puts the scroller all the way at the bottom which is problematic.

@jcolomb

This comment has been minimized.

Copy link

jcolomb commented Jul 5, 2018

Does not work in my hand, do I miss something?:

library(DT)
DeptEditDT <- datatable(
  iris, rownames=FALSE,
  extensions = list(Scroller=NULL,  FixedColumns=list(leftColumns=2)),
  options = list(
    dom = 'T<"clear">lfrtip',
    autoWidth = TRUE,
    columnDefs = list(list(width = '20%', targets = list(2,3,4))),
    deferRender=TRUE,
    scrollX=TRUE,scrollY=400,
    scrollCollapse=TRUE,
    pageLength = 100, lengthMenu = c(10,50,100,200)

  )
)
DeptEditDT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment