Skip to content

Commit a31fcaa

Browse files
AApuciArgoZhang
andauthored
fix(Table): include padding in auto-fit column width (#6876)
* Fix column width calculation to use header cell Updated autoFitColumnWidth to calculate the header cell width using the <th> element directly instead of querying for a child span. This ensures more accurate column width fitting when including the header. * refactor: 更改计算 theader 宽度逻辑 --------- Co-authored-by: Argo Zhang <[email protected]>
1 parent 96cc874 commit a31fcaa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ const autoFitColumnWidth = async (table, col) => {
745745
if (table.options.fitColumnWidthIncludeHeader) {
746746
const th = col.closest('th');
747747
const span = th.querySelector('.table-cell');
748-
maxWidth = Math.max(maxWidth, calcCellWidth(span));
748+
const thStyle = getComputedStyle(th);
749+
const margin = parseFloat(thStyle.getPropertyValue('padding-left')) + parseFloat(thStyle.getPropertyValue('padding-right'))
750+
maxWidth = Math.max(maxWidth, calcCellWidth(span)) + margin;
749751
}
750752

751753
if (table.options.autoFitColumnWidthCallback !== null) {

0 commit comments

Comments
 (0)