Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add MinWidth parameter to ColumnBase and use it in DataGrid resize ac…
…tions
  • Loading branch information
vnbaaij committed Sep 4, 2025
commit 59a65ea2cddc49bcd9379b9ebe24cf72b9e9f40b
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,14 @@
Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.MinWidth">
<summary>
Gets or sets the minimal width of the column.
Defaults to 100px for a regular column and 50px for a select column.
When resizing a column, the user will not be able to make it smaller than this value.
Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.Grid">
<summary>
Gets a reference to the enclosing <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1" />.
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Components/DataGrid/Columns/ColumnBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ public abstract partial class ColumnBase<TGridItem>
[Parameter]
public string? Width { get; set; }

/// <summary>
/// Gets or sets the minimal width of the column.
/// Defaults to 100px for a regular column and 50px for a select column.
/// When resizing a column, the user will not be able to make it smaller than this value.
/// Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'.
/// </summary>
[Parameter]
public string MinWidth { get; set; } = "100px";

/// <summary>
/// Gets a reference to the enclosing <see cref="FluentDataGrid{TGridItem}" />.
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions src/Core/Components/DataGrid/Columns/PropertyColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This file is licensed to you under the MIT License.
// ------------------------------------------------------------------------

using System.Linq.Expressions;
using System.Reflection;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.Infrastructure;
using Microsoft.FluentUI.AspNetCore.Components.Extensions;
using System.Linq.Expressions;
using System.Reflection;

namespace Microsoft.FluentUI.AspNetCore.Components;

Expand Down Expand Up @@ -119,7 +119,6 @@ protected override void OnParametersSet()
return (Func<TGridItem, string?>)method.Invoke(null, [getter, format])!;
}


if (typeof(IFormattable).IsAssignableFrom(typeof(TProp)))
{
//Struct
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/DataGrid/Columns/SelectColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class SelectColumn<TGridItem> : ColumnBase<TGridItem>, IDisposable
public SelectColumn()
{
Width = "50px";
MinWidth = "50px";
ChildContent = GetDefaultChildContent();

_itemsChanged = new(EventCallback.Factory.Create<object?>(this, UpdateSelectedItemsAsync));
Expand Down
7 changes: 3 additions & 4 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let grids = [];
const minWidth = 100;

export function init(gridElement, autoFocus) {
if (gridElement === undefined || gridElement === null) {
Expand Down Expand Up @@ -255,7 +254,7 @@ export function enableColumnResizing(gridElement, resizeColumnOnAllRows = true)
const diffX = isRTL ? pageX - e.pageX : e.pageX - pageX;
const column = columns.find(({ header }) => header === curCol);

column.size = parseInt(Math.max(minWidth, curColWidth + diffX), 10) + 'px';
column.size = parseInt(Math.max(parseInt(column.header.style.minWidth), curColWidth + diffX), 10) + 'px';

columns.forEach((col) => {
if (col.size.startsWith('minmax')) {
Expand Down Expand Up @@ -373,7 +372,7 @@ export function resizeColumnDiscrete(gridElement, column, change) {
const width = headerBeingResized.getBoundingClientRect().width + change;

if (change < 0) {
column.size = Math.max(minWidth, width) + 'px';
column.size = Math.max(parseInt(column.header.style.minWidth), width) + 'px';
}
else {
column.size = width + 'px';
Expand All @@ -400,7 +399,7 @@ export function resizeColumnExact(gridElement, column, width) {

grids.find(({ id }) => id === gridElement.id).columns.forEach(column => {
if (column.header === headerBeingResized) {
column.size = Math.max(minWidth, width) + 'px';
column.size = Math.max(parseInt(column.header.style.minWidth), width) + 'px';
}
else {
if (column.size.startsWith('minmax')) {
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/DataGrid/FluentDataGridCell.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public partial class FluentDataGridCell<TGridItem> : FluentComponentBase
.AddStyle("grid-column", GridColumn.ToString(), () => !Grid.EffectiveLoadingValue && (Grid.Items is not null || Grid.ItemsProvider is not null) && Grid.DisplayMode == DataGridDisplayMode.Grid)
.AddStyle("text-align", "center", Column is SelectColumn<TGridItem>)
.AddStyle("align-content", "center", Column is SelectColumn<TGridItem>)
.AddStyle("min-width", Column?.MinWidth, Owner.RowType == DataGridRowType.Header)
.AddStyle("padding-inline-start", "calc(((var(--design-unit)* 3) + var(--focus-stroke-width) - var(--stroke-width))* 1px)", Column is SelectColumn<TGridItem> && Owner.RowType == DataGridRowType.Default)
.AddStyle("padding-top", "calc(var(--design-unit) * 2.5px)", Column is SelectColumn<TGridItem> && (Grid.RowSize == DataGridRowSize.Medium || Owner.RowType == DataGridRowType.Header))
.AddStyle("padding-top", "calc(var(--design-unit) * 1.5px)", Column is SelectColumn<TGridItem> && Grid.RowSize == DataGridRowSize.Small && Owner.RowType == DataGridRowType.Default)
Expand Down
Loading