Giter VIP home page Giter VIP logo

Comments (20)

kdaily avatar kdaily commented on May 27, 2024 5

Same problem - must specify scrollX=TRUE.

from dt.

alexmosc avatar alexmosc commented on May 27, 2024 5

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%.

These suggestions do not seem to work when building an HTML markdown document. My table contains rather long texts, and the last column occupies like 50% of all the table, and I can't adjust it.

datatable( covered_tbl , rownames = F , escape = F , options = list( pageLength = 10 , scrollX = T , scrollY = T , autoWidth = T , columnDefs = list( list(targets=c(0), visible=TRUE, width='10%'), list(targets=c(1), visible=TRUE, width='10%'), list(targets=c(2), visible=TRUE, width='4%'), list(targets=c(3), visible=TRUE, width='38%'), list(targets=c(4), visible=TRUE, width='38%') ) ) )

from dt.

jcolomb avatar jcolomb commented on May 27, 2024 3

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

from dt.

yihui avatar yihui commented on May 27, 2024 2

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%.

from dt.

tsouchlarakis avatar tsouchlarakis commented on May 27, 2024 2

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.

from dt.

mtseman avatar mtseman commented on May 27, 2024

Yep. Works now. Thanks!

from dt.

zizaozi avatar zizaozi commented on May 27, 2024

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.

from dt.

jamiemkass avatar jamiemkass commented on May 27, 2024

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

from dt.

yihui avatar yihui commented on May 27, 2024

Same as ??

from dt.

thecharleschin avatar thecharleschin commented on May 27, 2024

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.

from dt.

samuel-bohman avatar samuel-bohman commented on May 27, 2024

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

from dt.

mjlarsen avatar mjlarsen commented on May 27, 2024

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.

from dt.

BJWiley233 avatar BJWiley233 commented on May 27, 2024

When I use scrollX=T this severely decrease width of my entire table to half the page and only half columns are now visible, however it does work for extending the column I wanted but have to scroll ALLLLLL the way over now to see half my columns. What happened? Without scollX the table is correctly the width of the screen.

from dt.

sanjmeh avatar sanjmeh commented on May 27, 2024

Neither adding scrollX=TRUE or scrollX=FALSE disables the horizontal scroller nor adjusts the column widths for me. Also if I give width = "600px" as an overall datatable option, the table is confined to a much smaller width (than 600px) and the X scroller invariabley appears regardless of scrollX=FALSE. I know there is a known issue and read through it but the workaround also doesn't seem to work.

from dt.

philibe avatar philibe commented on May 27, 2024

workaround for datatables with not too much datas:

datas<- ( datas
          %>% mutate (
            # you could also use a css class and / or add a div only for length string greater than n characters
            mycol1=paste0("<div style='white-space: normal;width: 50px;'>",mycol1,"</div>")
          )
)
escape_vector<- -(which(colnames(datas) %in% list("mycol1","mycol2" ))    +1)
res<-DT::datatable(  datas,
                     style = "bootstrap",   class = "compact", filter='top',
                     selection = c("single"),
                     escape= escape_vector,
[...]

from dt.

DOH-KGC0303 avatar DOH-KGC0303 commented on May 27, 2024

These suggestions do not seem to work when building an HTML markdown document. My table contains rather long texts, and the last column occupies like 50% of all the table, and I can't adjust it.

I am also building a table in an HTML markdown document and haven't been able to get any of these suggestions to work to change the widths of my columns.

from dt.

jzadra avatar jzadra commented on May 27, 2024

None of these suggestions are working for me either. The width of the column does not change regardless of the things listed here.

from dt.

shrektan avatar shrektan commented on May 27, 2024

This works for me.

DT::datatable(iris, options = list(columnDefs = list(list(targets = (3), width = "50%"))))       

from dt.

jzadra avatar jzadra commented on May 27, 2024

That also works for me. But for some reason it is not working with my data:

df <- structure(list(pageTitle = c("oi r—ovn  nngenWYeion  iP  0m corMiokgfrn mneCuoJW Kof oET rmao5orntnanOimtfe", 
                                   "dsote rPVertsoies’  n  e nasnuRge O  assOClInABsnIt1Dtor used9-nieg aetsMaC erlnolpVasu ", 
                                   "pgnhyToou hiftMtA   yCoHi   eheolEc o tn AeurlSonllrdct in f  aondWtaOaefuaogrsdas", 
                                   "AniiseMagee ecSEtaCoortse  nfig c:ganl stu aoctrr iientenAInioSa hnnnrsn urdce  Juiitcolrlci", 
                                   "sStnas C PssruslAM eardnVlEmsn:tinrtte in nAigtlaTeIas  Aaeye etegs", 
                                   "omogdai ea en   yerro CiiD Aoy pl fdioienlBtclsaTBahAcafrxmdo tnrfeoet", 
                                   "a deneayithegabteatcsNr eP  innsoAaeietetuno ra  S nCcCMad nueRrnloernaces ninsisaml  o PoewllAc", 
                                   "l—hccntDic itnWvtaoIe sAoaatupluaY ngTannC AYatplo in?no ureeri: ", 
                                   " PaefrbMleieirmpsmaeyen  l  ngeisBrai CEcrKlmLrSeE  eaAnN", 
                                   "a odHFegoatDdiStAoh ornmmsniultYyMoiisly i-te gitesun ", "WGW eerkRNetneet rwiwouAcodsaaas rG rirFdeea mDrlnauesvoinGtu  mk nsatAd", 
                                   "ice clIrsogtlftCniBA rrandhnP:neeFtP oeanneaPoto esCestara prasotS Ba tev en Aa", 
                                   " l tahddotnrt:FiSessaRGta Bwdeaaur Ianntg c  retd auWUreuegDA ", 
                                   "ast utisyWi:va ioteepohn reFll gIrnsdAdlUoe iitwhft stgrSs wnn aDagBedna", 
                                   "Vmm  Ts erlOoaiceeCe t AEiB i9snaeiaeR niC e ukCrnneoat kkn ne1DPXfe-  sCasOrFoOIPsnduthioicdraumtln"
), published = structure(c(18691, 18338, 18082, 18345, 18942, 
                           18967, 18843, 18039, 18683, 18366, 18232, 19026, 18974, 17667, 
                           18589), class = "Date"), views_all_time = c(125, 77, 63, 190, 
                                                                       158, 126, 98, 94, 77, 203, 75, 50, 148, 125, 49), views_zach_start = c(6, 
                                                                                                                                              12, 9, 9, 158, 126, 25, 9, 18, 11, 6, 50, 148, 27, 6), views_past30 = c(3, 
                                                                                                                                                                                                                      6, 3, 3, 12, 23, 15, 3, 9, 3, 3, 50, 46, 9, 3), views_past7 = c(0, 
                                                                                                                                                                                                                                                                                      3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 50, 0, 3, 0), views_this_week = c(0, 
                                                                                                                                                                                                                                                                                                                                                      0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 6, 0, 0, 0)), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                -15L), class = c("tbl_df", "tbl", "data.frame"))

DT::datatable(iris, 
              extensions = "Scroller",
              options = list(columnDefs = list(list(
                targets = (0), width = "50%"
              )),
              deferRender = TRUE,
              scrollY = 200,
              scroller = TRUE))       



DT::datatable(df, 
              extensions = "Scroller",
              options = list(columnDefs = list(list(
                targets = (0), width = "10%"
              )),
              deferRender = TRUE,
              scrollY = 200,
              scroller = TRUE))       

DT::datatable(df, 
              extensions = "Scroller",
              options = list(columnDefs = list(list(
                targets = (0), width = "50%"
              )),
              deferRender = TRUE,
              scrollY = 200,
              scroller = TRUE))       

from dt.

laugon10 avatar laugon10 commented on May 27, 2024

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%.

These suggestions do not seem to work when building an HTML markdown document. My table contains rather long texts, and the last column occupies like 50% of all the table, and I can't adjust it.

datatable( covered_tbl , rownames = F , escape = F , options = list( pageLength = 10 , scrollX = T , scrollY = T , autoWidth = T , columnDefs = list( list(targets=c(0), visible=TRUE, width='10%'), list(targets=c(1), visible=TRUE, width='10%'), list(targets=c(2), visible=TRUE, width='4%'), list(targets=c(3), visible=TRUE, width='38%'), list(targets=c(4), visible=TRUE, width='38%') ) ) )

Just the same for me. No matter what I have tried (everything mention here and elsewhere), with HTML markdown nothing works to obtain an specific width.

Is there any solution?

Thank you

from dt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.