Skip to content
Merged
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
28 changes: 18 additions & 10 deletions TablePro/Views/Results/DataGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ struct DataGridView: NSViewRepresentable {
tableView.removeTableColumn(column)
}

let willRestoreWidths = !columnLayout.columnWidths.isEmpty
for (index, columnName) in rowProvider.columns.enumerated() {
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("col_\(index)"))
column.title = columnName
Expand All @@ -384,11 +385,15 @@ struct DataGridView: NSViewRepresentable {
column.headerCell.setAccessibilityLabel(
String(localized: "Column: \(columnName)")
)
column.width = coordinator.cellFactory.calculateOptimalColumnWidth(
for: columnName,
columnIndex: index,
rowProvider: rowProvider
)
if willRestoreWidths {
column.width = columnLayout.columnWidths[columnName] ?? 100
} else {
column.width = coordinator.cellFactory.calculateOptimalColumnWidth(
for: columnName,
columnIndex: index,
rowProvider: rowProvider
)
}
column.minWidth = 30
column.resizingMask = .userResizingMask
column.isEditable = isEditable
Expand All @@ -397,6 +402,7 @@ struct DataGridView: NSViewRepresentable {
}
} else {
// Same column count — lightweight in-place update (avoids remove/add overhead)
let hasSavedWidths = !columnLayout.columnWidths.isEmpty
for column in tableView.tableColumns where column.identifier.rawValue != "__rowNumber__" {
guard let colIndex = Self.columnIndex(from: column.identifier),
colIndex < rowProvider.columns.count else { continue }
Expand All @@ -407,11 +413,13 @@ struct DataGridView: NSViewRepresentable {
?? rowProvider.columnTypes[colIndex].displayName
column.headerToolTip = "\(columnName) (\(typeName))"
}
column.width = coordinator.cellFactory.calculateOptimalColumnWidth(
for: columnName,
columnIndex: colIndex,
rowProvider: rowProvider
)
if !hasSavedWidths {
column.width = coordinator.cellFactory.calculateOptimalColumnWidth(
for: columnName,
columnIndex: colIndex,
rowProvider: rowProvider
)
}
column.isEditable = isEditable
}
}
Expand Down
Loading