Skip to content

Commit 0a30cb4

Browse files
committed
refactor: 增加固定列调整逻辑
1 parent 6e3b67d commit 0a30cb4

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/BootstrapBlazor/Components/Table/Table.razor.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,10 @@ const setResizeListener = table => {
586586
const marginX = eventX - originalX
587587
table.tables.forEach(t => {
588588
const group = [...t.children].find(i => i.nodeName === 'COLGROUP')
589+
const calcColWidth = colWidth + marginX;
589590
if (group) {
590591
const curCol = group.children.item(colIndex)
591-
curCol.style.width = `${colWidth + marginX}px`
592+
curCol.style.setProperty('width', `${calcColWidth}px`);
592593
const tableEl = curCol.closest('table')
593594
let width = tableWidth + marginX
594595
if (t.closest('.table-fixed-body')) {
@@ -606,6 +607,22 @@ const setResizeListener = table => {
606607
tip.update();
607608
}
608609
}
610+
611+
const header = col.parentElement;
612+
if (header.classList.contains('fixed')) {
613+
resizeNextFixedColumnWidth(header, calcColWidth);
614+
}
615+
}
616+
617+
const tbody = [...t.children].find(i => i.nodeName === 'TBODY');
618+
if (tbody) {
619+
const rows = [...tbody.children].filter(i => i.nodeName === 'TR');
620+
rows.forEach(row => {
621+
const header = row.children.item(colIndex);
622+
if (header.classList.contains('fixed')) {
623+
resizeNextFixedColumnWidth(header, calcColWidth);
624+
}
625+
});
609626
}
610627
})
611628
},
@@ -624,6 +641,25 @@ const setResizeListener = table => {
624641
})
625642
}
626643

644+
const resizeNextFixedColumnWidth = (col, width) => {
645+
if (col.classList.contains('fixed-right')) {
646+
const nextColumn = col.previousElementSibling;
647+
if (nextColumn.classList.contains('fixed')) {
648+
const right = parseFloat(col.style.getPropertyValue('right'));
649+
nextColumn.style.setProperty('right', `${right + width}px`);
650+
resizeNextFixedColumnWidth(nextColumn, nextColumn.offsetWidth);
651+
}
652+
}
653+
else if (col.classList.contains('fixed')) {
654+
const nextColumn = col.nextElementSibling;
655+
if (nextColumn.classList.contains('fixed')) {
656+
const left = parseFloat(col.style.getPropertyValue('left'));
657+
nextColumn.style.setProperty('left', `${left + width}px`);
658+
resizeNextFixedColumnWidth(nextColumn, nextColumn.offsetWidth);
659+
}
660+
}
661+
}
662+
627663
const setColumnResizingListen = (table, col) => {
628664
if (table.options.showColumnWidthTooltip) {
629665
EventHandler.on(col, 'mouseenter', e => {

0 commit comments

Comments
 (0)