Skip to content

Commit 0d05de6

Browse files
committed
feat: 增加 OnAutoFitContentAsync 回调
1 parent 0cfe26c commit 0d05de6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,10 @@ const indexOfCol = col => {
714714

715715
const autoFitColumnWidth = async (table, col) => {
716716
const field = col.getAttribute('data-bb-field');
717-
const widthValue = await table.invoke.invokeMethodAsync(table.options.autoFitContentCallback, field);
717+
let widthValue = 0;
718+
if (table.options.autoFitContentCallback !== null) {
719+
widthValue = await table.invoke.invokeMethodAsync(table.options.autoFitContentCallback, field);
720+
}
718721

719722
const index = indexOfCol(col);
720723
let rows = null;
@@ -725,11 +728,13 @@ const autoFitColumnWidth = async (table, col) => {
725728
rows = table.tables[0].querySelectorAll('table > tbody > tr:not(.is-detail)');
726729
}
727730

728-
let maxWidth = 0;
729-
[...rows].forEach(row => {
730-
const cell = row.cells[index];
731-
maxWidth = Math.max(maxWidth, calcCellWidth(cell));
732-
});
731+
let maxWidth = widthValue;
732+
if (maxWidth === 0) {
733+
[...rows].forEach(row => {
734+
const cell = row.cells[index];
735+
maxWidth = Math.max(maxWidth, calcCellWidth(cell));
736+
});
737+
}
733738

734739
if (maxWidth > 0) {
735740
table.tables.forEach(table => {

0 commit comments

Comments
 (0)