Skip to content

Commit

Permalink
fix(module: table): resizable table with ScrollY (#3746)
Browse files Browse the repository at this point in the history
* fix(module: table): resizable table with ScrollY

* fix lint

* fix resizable table with both scroll x and y

* fix test

---------

Co-authored-by: James Yeung <shunjiey@hotmail.com>
Co-authored-by: thirking <king2381955@sina.com>
  • Loading branch information
3 people committed Mar 21, 2024
1 parent e1ec721 commit 158bb07
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions components/core/JsInterop/modules/components/tableHelper.ts
Expand Up @@ -18,7 +18,7 @@
window.addEventListener('resize', bodyRef.bindScroll);

if (resizable) {
tableHelper.enableColumnResizing(tableRef);
tableHelper.enableColumnResizing(headerRef, tableRef, scrollY);
}
}

Expand Down Expand Up @@ -59,13 +59,18 @@
pingRight ? wrapperRef.classList.add("ant-table-ping-right") : wrapperRef.classList.remove("ant-table-ping-right");
}

static enableColumnResizing(tableElement) {
static enableColumnResizing(headerElement, tableElement, scrollY) {

const cols = tableElement.querySelectorAll('col');
const ths = scrollY ?
headerElement.querySelectorAll('.ant-table-thead th') :
tableElement.tHead.querySelectorAll('.ant-table-thead th');
const headerCols = scrollY ? headerElement.querySelectorAll('col') : null;

tableElement.tHead.querySelectorAll('.ant-table-thead th').forEach((th, i) => {
ths.forEach((th, i) => {

const col = cols[i];
const headerCol = headerCols ? headerCols[i] : null;
const handle = document.createElement('div');
handle.classList.add('ant-table-resizable-handle');
handle.style.height = `${tableElement.offsetHeight}px`;
Expand Down Expand Up @@ -104,6 +109,9 @@
if (updatedColumnWidth > 0) {
th.style.width = `${updatedColumnWidth}px`;
col.style.width = `${updatedColumnWidth}px`;
if (headerCol) {
headerCol.style.width =`${updatedColumnWidth}px`;
}
handle.style.right = '0';
handle.style.left = '';
handle.classList.remove('ant-table-resizing');
Expand Down

0 comments on commit 158bb07

Please sign in to comment.