fluentui-blazor
fluentui-blazor copied to clipboard
DataGrid Sorting Comparer is Persisting , When Changing the Grid Items source
🐛 Bug Report
Actually this issue is noticed when changing the Grid Source Items and when the Sorting is enabled ,Even though I changed the Columns its still keeping the old object and keeping the Sorting enabled as it is ,To See that Please remove ErrorBoundary in Layout. To Replicate the Issue.
- First Select an option other than Customer .
- After that Select any Column Other than "ID" for sorting . (Note : ID is common to all the grid source it will work).
- Then Select PriceList or Customer option in ComboBox.
- You will get the error.
Error:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The given key 'Price' was not present in the dictionary.
System.Collections.Generic.KeyNotFoundException: The given key 'Price' was not present in the dictionary.
at System.Collections.Generic.Dictionary
2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Item(String key) at System.Object.lambda_method23(Closure , Dictionary
2 ) at Microsoft.FluentUI.AspNetCore.Components.PropertyColumn2.<>c__DisplayClass23_1[[System.Collections.Generic.Dictionary
2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0,
💻 Repro or Code Sample
Please Use the below code as reference for recreating the issue. And Please Remove ## from below Code.
##<FluentStack Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Center" ##HorizontalAlignment="HorizontalAlignment.Start" VerticalGap="20"> ##<FluentSelect @onchange="DropDownChanged" Class="textFeildEdit" Style="min-width:280px" Items=@comboBox ##Label="Select Table" ## OptionText="@(i => i.Text)" ##OptionValue="@(i => i.Value)" ##OptionSelected="@(i => i.Selected)" /> ##@if(display){
<FluentDataGrid Items="gridSource">
## @foreach(string column in ColumnNames)
## {
## <PropertyColumn Sortable="true" Property="@(p=>p[column])" Title="@column"></PropertyColumn>
##}
##</FluentDataGrid>
##}
##</FluentStack>
@code{
IQueryable<Dictionary<string, object>> gridSource;
List<string> ColumnNames = new List<string>();
bool display;
private List<Option<string>> comboBox = new List<Option<string>>
{
new Option<string>(){Value ="Customer", Text="Customer", Selected=true},
new Option<string>(){Value="Product",Text="Product",Selected=false},
new Option<string>(){Value="PriceList",Text="PriceList",Selected=false}
};
protected override async Task OnInitializedAsync()
{
display = false;
}
public async Task DropDownChanged(ChangeEventArgs args)
{
Console.WriteLine(args.Value);
if (args.Value.Equals("Customer"))
{
ColumnNames = GetCustomers()[0].Keys.ToList();
gridSource = GetCustomers().AsQueryable();
display = true;
await InvokeAsync(() => StateHasChanged());
}
else if (args.Value.Equals("Product"))
{
ColumnNames = GetProducts()[0].Keys.ToList();
gridSource = GetProducts().AsQueryable();
display = true;
await InvokeAsync(() => StateHasChanged());
}
else if (args.Value.Equals("PriceList"))
{
ColumnNames = GetPriceList()[0].Keys.ToList();
gridSource = GetPriceList().AsQueryable();
display = true;
await InvokeAsync(() => StateHasChanged());
}
}
List<Dictionary<string,object>> GetPriceList()
{
List<Dictionary<string, object>> priceList = new List<Dictionary<string, object>>();
Dictionary<string, object> PriceList1 = new Dictionary<string, object>();
PriceList1.Add("ID", 1);
PriceList1.Add("Product", "PHONE");
PriceList1.Add("Price", 20000);
Dictionary<string, object> PriceList2 = new Dictionary<string, object>();
PriceList2.Add("ID", 2);
PriceList2.Add("Product", "COOL");
PriceList2.Add("Price", 30000);
Dictionary<string, object> PriceList3 = new Dictionary<string, object>();
PriceList3.Add("ID", 3);
PriceList3.Add("Product", "AC");
PriceList3.Add("Price", 40000);
priceList.Add(PriceList1);
priceList.Add(PriceList2);
priceList.Add(PriceList3);
return priceList;
}
List<Dictionary<string,object>> GetProducts()
{
List<Dictionary<string, object>> product = new List<Dictionary<string, object>>();
Dictionary<string, object> Product1 = new Dictionary<string, object>();
Product1.Add("ID", 1);
Product1.Add("Name", "Cellphone");
Product1.Add("ProductId", "PHONE");
Dictionary<string, object> Product2 = new Dictionary<string, object>();
Product2.Add("ID", 2);
Product2.Add("Name", "Fridge");
Product2.Add("ProductId", "COOL");
Dictionary<string, object> Product3 = new Dictionary<string, object>();
Product3.Add("ID", 3);
Product3.Add("Name", "AirConditioner");
Product3.Add("ProductId", "AC");
product.Add(Product1);
product.Add(Product2);
product.Add(Product3);
return product;
}
List<Dictionary<string,object>> GetCustomers(){
List<Dictionary<string, object>> customer = new List<Dictionary<string, object>>();
Dictionary<string, object> Customer1 = new Dictionary<string, object>();
Customer1.Add("ID", 1);
Customer1.Add("MobileNo", 1234567890);
Customer1.Add("Name", "Delta");
Dictionary<string, object> Customer2 = new Dictionary<string, object>();
Customer2.Add("ID", 2);
Customer2.Add("MobileNo", 0987654321);
Customer2.Add("Name", "Alpha");
customer.Add(Customer1);
customer.Add(Customer2);
return customer;
}
}
🤔 Expected Behavior
If I change the Source Items and Columns ,It Should work as per the given items ,not as old items. And Sorting should be disable
😯 Current Behavior
💁 Possible Solution
Need to delete the Object ,When Item Source is changed.
Please supply working minimal reproduction code. Supplied code is inclomplete/gives errors
Closing due to inactivity. Can re-opened when reproduction code is available