From 25e6d641ed56eecee9fd62186c0854ed08cfa35f Mon Sep 17 00:00:00 2001 From: David Moreira Date: Mon, 25 Nov 2024 09:46:50 +0000 Subject: [PATCH] DataGrid: DataGridSelectEdit | Always refresh selectItems if Data count has changed (#5868) * DataGridSelectEdit | Always refresh selectItems if Data count has changed * Revert "DataGridSelectEdit | Always refresh selectItems if Data count has changed" This reverts commit 9924d772d873ab73dc7b47428abcd6b07b5b0735. * DataGridSelectEdit | Always refresh selectItems if Data count has changed * cleanup directives * cleanup directives * remove spaces from directives --- .../_DataGridCellSelectEdit.razor.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Extensions/Blazorise.DataGrid/_DataGridCellSelectEdit.razor.cs b/Source/Extensions/Blazorise.DataGrid/_DataGridCellSelectEdit.razor.cs index 698032a4f2..fd2fc9d501 100644 --- a/Source/Extensions/Blazorise.DataGrid/_DataGridCellSelectEdit.razor.cs +++ b/Source/Extensions/Blazorise.DataGrid/_DataGridCellSelectEdit.razor.cs @@ -22,6 +22,7 @@ private class SelectItem public string Text { get; private set; } public object Value { get; private set; } public bool Disabled { get; private set; } + public SelectItem( string text, object value, bool disabled ) { Text = text; @@ -39,8 +40,12 @@ public SelectItem( string text, object value, bool disabled ) protected override void OnInitialized() { elementId = IdGenerator.Generate; + base.OnInitialized(); + } - if ( Column.Data is not null ) + protected override void OnParametersSet() + { + if ( Column?.Data is not null && selectItems?.Count != Column.Data.Count() ) { selectItems = new(); foreach ( var item in Column.Data ) @@ -51,8 +56,7 @@ protected override void OnInitialized() selectItems.Add( new( text, value, disabled ) ); } } - - base.OnInitialized(); + base.OnParametersSet(); } private void OnSelectedValueChanged( object value ) @@ -92,7 +96,6 @@ protected override async Task OnAfterRenderAsync( bool firstRender ) { await Focus(); } - } } await base.OnAfterRenderAsync( firstRender ); @@ -115,6 +118,7 @@ public async Task Select() [CascadingParameter] public DataGrid ParentDataGrid { get; set; } [Inject] public IIdGenerator IdGenerator { get; set; } + /// /// Gets or sets the instance. ///