Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ private async Task OnTableRenderAsync(bool firstRender)
await InvokeVoidAsync("init", Id, Interop, new
{
DragColumnCallback = nameof(DragColumnCallback),
AutoFitContentCallback = nameof(AutoFitContentCallback),
AutoFitContentCallback = OnAutoFitContentAsync == null ? null : nameof(AutoFitContentCallback),
ResizeColumnCallback = OnResizeColumnAsync != null ? nameof(ResizeColumnCallback) : null,
ColumnMinWidth = ColumnMinWidth ?? Options.CurrentValue.TableSettings.ColumnMinWidth,
ScrollWidth = ActualScrollWidth,
Expand Down
17 changes: 11 additions & 6 deletions src/BootstrapBlazor/Components/Table/Table.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,10 @@ const indexOfCol = col => {

const autoFitColumnWidth = async (table, col) => {
const field = col.getAttribute('data-bb-field');
const widthValue = await table.invoke.invokeMethodAsync(table.options.autoFitContentCallback, field);
let widthValue = 0;
if (table.options.autoFitContentCallback !== null) {
widthValue = await table.invoke.invokeMethodAsync(table.options.autoFitContentCallback, field);
}

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

let maxWidth = 0;
[...rows].forEach(row => {
const cell = row.cells[index];
maxWidth = Math.max(maxWidth, calcCellWidth(cell));
});
let maxWidth = widthValue;
if (maxWidth === 0) {
[...rows].forEach(row => {
const cell = row.cells[index];
maxWidth = Math.max(maxWidth, calcCellWidth(cell));
});
}

if (maxWidth > 0) {
table.tables.forEach(table => {
Expand Down
Loading