Skip to content

Commit

Permalink
make column reordering and regenerating fast
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Jan 23, 2024
1 parent 200ca0c commit 3be7574
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 346 deletions.
23 changes: 19 additions & 4 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ private DataGridCell CreateHeaderCell(DataGridColumn column)
Grid.SetColumn(column.SortingIconContainer, 1);
}

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

private void InitHeaderView()
Expand All @@ -1407,8 +1407,6 @@ private void InitHeaderView()

SetColumnsBindingContext();

_headerView.Children.Clear();

if (Columns == null)
{
_headerView.ColumnDefinitions.Clear();
Expand Down Expand Up @@ -1445,7 +1443,24 @@ private void InitHeaderView()
col.HeaderView.UpdateBindings(this, HeaderBordersVisible);

Grid.SetColumn(col.HeaderView, i);
_headerView.Children.Add(col.HeaderView);

if (_headerView.Children.TryGetItem(i, out var existingCell))
{
if (existingCell is not DataGridCell cell)
{
throw new InvalidDataException($"{nameof(DataGridRow)} should only contain {nameof(DataGridCell)}s");
}

if (cell.Column != col)
{
_headerView.Children[i] = col.HeaderView;
}
}
else
{
_headerView.Children.Add(col.HeaderView);
}

}

// Remove extra columns
Expand Down
13 changes: 12 additions & 1 deletion Maui.DataGrid/DataGridCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ namespace Maui.DataGrid;
/// </summary>
internal sealed class DataGridCell : Grid
{
internal DataGridCell(View cellContent, Color? backgroundColor)
internal DataGridCell(View cellContent, Color? backgroundColor, DataGridColumn column, bool isEditing)

{
var colorfulCellContent = new ContentView
{
BackgroundColor = backgroundColor,
Content = cellContent,
};

Content = cellContent;
Column = column;
IsEditing = isEditing;

Children.Add(colorfulCellContent);
}

public View Content { get; }

public DataGridColumn Column { get; }
public bool IsEditing { get; }


internal void UpdateBindings(DataGrid dataGrid, bool bordersVisible = true)
{
// The DataGridCell is a grid, and the padding constitutes the cell's border
Expand Down
Loading

0 comments on commit 3be7574

Please sign in to comment.