DataTables / DataTablesSrc

DataTables source repository
https://datatables.net
MIT License
637 stars 425 forks source link

Pagination widget does not render page buttons correctly if table is initially hidden #295

Closed xPaw closed 1 month ago

xPaw commented 1 month ago

Repro: https://jsfiddle.net/90o3t51h/

$("#example").DataTable({
  initComplete() {
    document.body.hidden = false
  }
})

I am initially hiding the table, and when the init is complete I show it, but for some reason it only shows one page button:

image

Switching the page will update it and show all the other buttons:

image

Seems to be a problem introduced in v2. This works fine in v1: https://jsfiddle.net/90o3t51h/1/

AllanJard commented 1 month ago

This is expected and is due to the responsive nature of the control. If an element is hidden it has no height / width and therefore the responsive calculations can't be made. You need to call the draw() method when your table is made visible.

https://jsfiddle.net/wxLj9q25/

xPaw commented 1 month ago

Ahh, it's because of the responsiveness, that would make sense. Thanks.

xPaw commented 1 month ago

https://github.com/DataTables/DataTablesSrc/blob/643377800fbf3b1e050b8d59a843837710aea693/js/features/features.page.js#L155

Would it be reasonable to check $(host).height() > 0 or $(buttonEls[0]).outerHeight() > 0 here first? I am looking at the stack trace, it keeps trying to render buttons until it hits 1 and can't go lower any more.

AllanJard commented 1 month ago

Yup, I like that - thanks for the suggestion. Committed here.

xPaw commented 1 month ago

that buttonEls[0] access should be after buttonEls.length check.

AllanJard commented 1 month ago

oh - damn. Thanks! Fixed.

Need to check why the unit tests didn't catch that...