jerrylow / basictable

Basic Table jQuery or Vanilla JS plugin for simple responsive tables.
MIT License
127 stars 57 forks source link

replace viewport offset with offset relative to parent #34

Closed cr0ybot closed 1 year ago

cr0ybot commented 1 year ago

Replace table.getBoundingClientRect().left (viewport offset) with table.offsetLeft (parent offset) in table width calculation.

Fixes #33

jerrylow commented 1 year ago

Actually after some re-testing, trying to figure out the parent with padding I realize we don't actually need the offset anymore, we just need to compare the table width with the parent, similar to what I originally had in the jQuery version. Here's the updated:

table-resize

cr0ybot commented 1 year ago

I think it is still possible for the table itself to be offset from its parent via margin or other means, so the offset from the parent may still be relevant, particularly if that margin is a fixed width.

jerrylow commented 1 year ago

@cr0ybot ah I see, you are right but I think just relying on offset left is still not sufficient as it doesn't consider the right side if it's overflowing or not. The fix ATM is more accurate if there are no inner offset from the table, but does overlook the scenarios that you mentioned. Let me think through this a bit more.