Table informing if it has a scrollbar

Table informing if it has a scrollbar

marceltpomarceltpo Posts: 5Questions: 1Answers: 2
edited May 2018 in Free community support

Hello everyone,

I'm having layout problems (but specifically header formatting) with a datatable after including a scrollbar in it. I even managed to get the table to render itself satisfactorily when the scrollbar was present. The problem was that when the scrollbar didn't appear, the code I did ended up harming the layout of the table.

I would like to know if there is any method or attribute on the part of the table where I can know if the scrollbar is present or not. Knowing if the scroll is present or not, it is easy to apply the formatting codes.

Observation: this table of my it is updated from time to time to receive data. And always in the second update, it is rendered with the correct layout (it only gets the layout broken in the first rendering). Does anyone have any idea why this?

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @marceltpo ,

    That second update does seem odd being correct does seem odd. We're happy to take a look if you could link to the page.

    Cheers,

    Colin

  • marceltpomarceltpo Posts: 5Questions: 1Answers: 2

    Hi @colin, here's a example of what i was saying about the observation:

    In the first rendering of the table, the headers always get this crap. When the table refreshes (when I click on the header, for example), then it stays the correct way.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @marceltpo ,

    We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • marceltpomarceltpo Posts: 5Questions: 1Answers: 2

    Hi @colin,

    It will be very difficult to create the conditions in another code to show the problem I am currently having. However, maybe you can help me with something else: what is the code that is executed when we click on the header of the table?

    Like happens in https://datatables.net/forums/discussion/41587, when I click in header, the layout of header back to normal.

  • marceltpomarceltpo Posts: 5Questions: 1Answers: 2
    Answer ✓

    I discovered the reason for my header rendering problem. As in example (https://datatables.net/forums/discussion/41587), my datatable was not visible when it was started (it was in a modal window). Then I realized that it could only render without any problem when the window was active and the view.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah, yep, glad to hear you got it sorted!

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Yes, when the table is made visible you need to call columns.adjust() to tell DataTables that it is now visible.

    I've got a plan for v2 to make that automatic... :)

    Allan

  • marceltpomarceltpo Posts: 5Questions: 1Answers: 2
    edited June 2018 Answer ✓

    Hi @allan

    I got to use this API solution (columns.adjust()), but I was calling the method when the window wasn't visible. And seeing now, it makes perfect sense not to have worked before. :D

    Thanks by the tip. :)

This discussion has been closed.