Browse Source
Fix nth child selector in data grid header (#15482 )
* Removed index to display index map so that nth child selector can work with current data.
* Iterate to find the index of the column taking visibility into account.
* Don't rely on VisibleColumnCount since it is updated later.
* Don't take visibility into account when evaluating nth-child and nth-last-child.
pull/14653/merge
Johan Appelgren
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
4 additions and
12 deletions
src/Avalonia.Controls.DataGrid/DataGridColumnCollection.cs
src/Avalonia.Controls.DataGrid/Primitives/DataGridCellsPresenter.cs
src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs
@ -12,7 +12,6 @@ namespace Avalonia.Controls
{
internal class DataGridColumnCollection : ObservableCollection < DataGridColumn >
{
private readonly Dictionary < int , int > _ columnsMap = new Dictionary < int , int > ( ) ;
private readonly DataGrid _ owningGrid ;
public DataGridColumnCollection ( DataGrid owningGrid )
@ -280,12 +279,10 @@ namespace Avalonia.Controls
VisibleStarColumnCount = 0 ;
VisibleEdgedColumnsWidth = 0 ;
VisibleColumnCount = 0 ;
_ columnsMap . Clear ( ) ;
for ( int columnIndex = 0 ; columnIndex < ItemsInternal . Count ; columnIndex + + )
{
var item = ItemsInternal [ columnIndex ] ;
_ columnsMap [ columnIndex ] = item . DisplayIndex ;
if ( item . IsVisible )
{
VisibleColumnCount + + ;
@ -299,11 +296,6 @@ namespace Avalonia.Controls
}
}
internal int GetColumnDisplayIndex ( int columnIndex )
{
return _ columnsMap . TryGetValue ( columnIndex , out var displayIndex ) ? displayIndex : - 1 ;
}
internal DataGridColumn GetColumnAtDisplayIndex ( int displayIndex )
{
if ( displayIndex < 0 | | displayIndex > = ItemsInternal . Count | | displayIndex > = DisplayIndexMap . Count )
@ -53,13 +53,13 @@ namespace Avalonia.Controls.Primitives
int IChildIndexProvider . GetChildIndex ( ILogical child )
{
return child is DataGridCell cell
? OwningGrid . ColumnsInternal . GetColumnDisplayIndex ( cell . ColumnIndex )
? cell . OwningColumn ? . DisplayIndex ? ? - 1
: throw new InvalidOperationException ( "Invalid cell type" ) ;
}
bool IChildIndexProvider . TryGetTotalCount ( out int count )
{
count = OwningGrid . ColumnsInternal . VisibleColumnCount ;
count = Children . Count - 1 ; // Adjust for filler column
return true ;
}
@ -118,13 +118,13 @@ namespace Avalonia.Controls.Primitives
int IChildIndexProvider . GetChildIndex ( ILogical child )
{
return child is DataGridColumnHeader header
? OwningGrid . ColumnsInternal . GetColumnDisplayIndex ( header . ColumnIndex )
? header . OwningColumn ? . DisplayIndex ? ? - 1
: throw new InvalidOperationException ( "Invalid cell type" ) ;
}
bool IChildIndexProvider . TryGetTotalCount ( out int count )
{
count = OwningGrid . ColumnsInternal . VisibleColumnCount ;
count = Children . Count - 1 ; // Adjust for filler column
return true ;
}