From 646d8d8c64358c64c43a970a5456452652f8ff01 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 26 May 2026 16:02:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Table=20?= =?UTF-8?q?=E5=88=97=E6=98=BE=E7=A4=BA=E9=9A=90=E8=97=8F=E6=97=B6=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E4=B8=BA=E9=9B=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Table/Table.razor | 1 + .../Components/Table/Table.razor.js | 64 ++++++++++++++----- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/BootstrapBlazor/Components/Table/Table.razor b/src/BootstrapBlazor/Components/Table/Table.razor index 9d8e0381c15..6e4680e0fcb 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor +++ b/src/BootstrapBlazor/Components/Table/Table.razor @@ -308,6 +308,7 @@ var displayName = col.GetDisplayName();
diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.js b/src/BootstrapBlazor/Components/Table/Table.razor.js index bee4d083652..47050acd5f6 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.js +++ b/src/BootstrapBlazor/Components/Table/Table.razor.js @@ -579,25 +579,11 @@ const autoFitColumnWidth = async (table, col) => { const field = col.getAttribute('data-bb-field'); const index = indexOfCol(col); let rows = null; - if (table.thead) { - rows = [...table.tables[1].tBodies[0].rows].filter(x => !x.classList.contains('is-detail')); - } - else { - rows = [...table.tables[0].tBodies[0].rows].filter(x => !x.classList.contains('is-detail')); - } - - let maxWidth = 0; - rows.forEach(row => { - const cell = row.cells[index]; - maxWidth = Math.max(maxWidth, calcCellWidth(cell)); - }); - + let maxWidth = getColumnMaxCellWidth(table, index); + if (table.options.fitColumnWidthIncludeHeader) { const th = col.closest('th'); - const span = th.querySelector('.table-cell'); - const thStyle = getComputedStyle(th); - const margin = parseFloat(thStyle.getPropertyValue('padding-left')) + parseFloat(thStyle.getPropertyValue('padding-right')) - maxWidth = Math.max(maxWidth, calcCellWidth(span) + margin); + maxWidth = Math.max(maxWidth, getCellWidth(th)); } if (maxWidth > 0) { @@ -626,6 +612,31 @@ const autoFitColumnWidth = async (table, col) => { } } +const getColumnMaxCellWidth = (table, index) => { + let rows = null; + let maxWidth = 0; + if (table.thead) { + rows = [...table.tables[1].tBodies[0].rows].filter(x => !x.classList.contains('is-detail')); + } + else { + rows = [...table.tables[0].tBodies[0].rows].filter(x => !x.classList.contains('is-detail')); + } + + rows.forEach(row => { + const cell = row.cells[index]; + maxWidth = Math.max(maxWidth, calcCellWidth(cell)); + }); + + return maxWidth; +} + +const getCellWidth = cell => { + const span = cell.querySelector('.table-cell'); + const cellStyle = getComputedStyle(cell); + const margin = parseFloat(cellStyle.getPropertyValue('padding-left')) + parseFloat(cellStyle.getPropertyValue('padding-right')) + return calcCellWidth(span) + margin; +} + const formControlSelector = 'input.form-control:not([type="hidden"]), textarea.form-control'; const getHorizontalWidth = style => { @@ -1090,6 +1101,9 @@ const resetColumnListPopover = table => { const resetColumns = (table, options) => { setResizeListener(table); + console.log(table, options); + setColSize(table, options); + const { columnStates, allowDragColumn } = options; const { options: { tableName } } = table; if (tableName) { @@ -1102,6 +1116,22 @@ const resetColumns = (table, options) => { } } +const setColSize = (table, options) => { + var zeroWidthColumns = options.columnStates.filter(i => i.width === null && i.visible === true); + zeroWidthColumns.forEach(col => { + const headerCollection = [...table.tables[0].querySelectorAll('thead > tr > th')]; + const th = headerCollection.find(i => i.getAttribute('data-bb-field') === col.name); + if (th.offsetWidth === 0) { + const width = getCellWidth(th); + const colIndex = headerCollection.indexOf(th); + col.width = Math.max(width, getColumnMaxCellWidth(table, colIndex)); + table.tables.forEach(table => { + table.querySelectorAll('colgroup col')[colIndex].style.width = `${col.width}px`; + }); + } + }); +} + const updateSortTooltip = table => { const el = table.el const span = el.querySelector('.sortable .table-text[aria-describedby]') From 00f1a04165ccaf1fe403018de36e112342e8266a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 26 May 2026 16:10:19 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=E7=A7=BB=E5=8A=A8=20data-bb-fi?= =?UTF-8?q?eld=20=E5=88=B0=20th=20=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Table/Table.razor | 4 +-- .../Components/Table/Table.razor.js | 34 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/Components/Table/Table.razor b/src/BootstrapBlazor/Components/Table/Table.razor index 6e4680e0fcb..ebae893fcc0 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor +++ b/src/BootstrapBlazor/Components/Table/Table.razor @@ -365,7 +365,7 @@ FallbackPlacements="@(["bottom", "auto"])" CustomClass="popover-table-column-toolbox" class="toolbox-icon" @onclick:stopPropagation> - +