Skip to content

Commit

Permalink
add placeholder space when column has filtering disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Oct 21, 2024
1 parent 376ff7a commit 74636a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Maui.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ public DataGridColumn()
VerticalOptions = LayoutOptions.Center,
};

FilterTextboxContainer = new ContentView();

FilterTextbox.SetBinding(Entry.TextProperty, new Binding(nameof(FilterText), BindingMode.TwoWay, source: this));
}

Expand Down Expand Up @@ -406,6 +408,8 @@ public Style HeaderFilterStyle

internal Label HeaderLabel { get; } = new();

internal ContentView FilterTextboxContainer { get; }

internal View SortingIconContainer { get; }

internal SortingOrder SortingOrder { get; set; }
Expand Down
37 changes: 29 additions & 8 deletions Maui.DataGrid/DataGridHeaderRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ private void OnVisibilityChanged(object? sender, EventArgs e)

private DataGridCell CreateHeaderCell(DataGridColumn column)
{
var filteringEnabled = DataGrid.FilteringEnabled && column.FilteringEnabled;

if (column.HeaderCell != null)
{
column.FilterTextbox.IsVisible = filteringEnabled;
SetFilterRow(column);

return column.HeaderCell;
}

Expand Down Expand Up @@ -214,15 +213,37 @@ private DataGridCell CreateHeaderCell(DataGridColumn column)
CommandParameter = column,
});

/* Configure the filter textbox */
SetFilterRow(column);

column.FilterTextbox.IsVisible = filteringEnabled;
cellContent.Children.Add(column.FilterTextbox);
cellContent.SetRow(column.FilterTextbox, 1);
cellContent.SetColumnSpan(column.FilterTextbox, 2);
cellContent.Children.Add(column.FilterTextboxContainer);
cellContent.SetRow(column.FilterTextboxContainer, 1);
cellContent.SetColumnSpan(column.FilterTextboxContainer, 2);

return new DataGridCell(cellContent, DataGrid.HeaderBackground, column, false);
}

private void SetFilterRow(DataGridColumn column)
{
if (DataGrid.FilteringEnabled && column.FilteringEnabled)
{
column.FilterTextboxContainer.Content = column.FilterTextbox;
}
else if (DataGrid.FilteringEnabled && DataGrid.Columns.Any(c => c.FilteringEnabled))
{
var height = DataGrid.Columns.First(c => c.FilteringEnabled).FilterTextbox.Height;

// Add placeholder
column.FilterTextboxContainer.Content = new BoxView
{
MinimumHeightRequest = height,
Color = Colors.Transparent,
};
}
else
{
column.FilterTextboxContainer.Content = null;
}
}

#endregion Methods
}

0 comments on commit 74636a6

Please sign in to comment.