When using an AutoComplete control inside a Grid columns edit template it will throw the error below when you click the Add button to add a new row.
Error:
System.Text.Json.JsonException: 'A' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
Repro code:
@page "/Test"
<h3>Test</h3>
@using Syncfusion.Blazor.Grids
<SfGrid DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" TValue="Order">
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings>
<GridColumns>
<GridColumn Field="Name" HeaderText="Name" Width="150"></GridColumn>
<GridColumn Field="Country.Name" HeaderText="Country" Width="150">
<EditTemplate>
<SfAutoComplete TItem="Country" TValue="Country" ID="Id" @bind-value="@((context as Order).Country)" DataSource="Countries">
<AutoCompleteFieldSettings Text="Name" Value="Code"></AutoCompleteFieldSettings>
</SfAutoComplete>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code {
private Country selectedCountry { get; set; }
public class Country
{
public string Name { get; set; }
public string Code { get; set; }
}
public static List<Country> Countries = new List<Country>
{
new Country() { Name = "Australia", Code = "AU" },
new Country() { Name = "Bermuda", Code = "BM" },
new Country() { Name = "Canada", Code = "CA" }
};
public class Order
{
public string Name { get; set; }
public Country Country { get; set; }
}
public List<Order> Orders = new List<Order>()
{
new Order() { Name = "First", Country = Countries[0] },
new Order() { Name = "Second", Country = Countries[1] },
new Order() { Name = "Third", Country = Countries[2] }
};
protected override void OnInitialized() => selectedCountry = Countries[1];
}
Repro steps:
| <SfGrid DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" TValue="Order"> <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings> <GridColumns> <GridColumn Field="Name" HeaderText="Name" Width="150"></GridColumn> <GridColumn Field="Country.Name" HeaderText="Country" Width="150"> <EditTemplate> <SfAutoComplete TItem="Country" TValue="string" ID="Id" @bind-value="@((context as Order).Country.Name)" DataSource="@Countries"> <AutoCompleteFieldSettings Text="Name" Value="Name"></AutoCompleteFieldSettings> </SfAutoComplete> </EditTemplate> </GridColumn> </GridColumns> </SfGrid> @code { private Country selectedCountry { get; set; } public class Country { public string Name { get; set; } public string Code { get; set; } } public static List<Country> Countries = new List<Country> { new Country() { Name = "Australia", Code = "AU" }, new Country() { Name = "Bermuda", Code = "BM" }, new Country() { Name = "Canada", Code = "CA" } }; public class Order { public string Name { get; set; } public Country Country { get; set; } } public List<Order> Orders = new List<Order>() { new Order() { Name = "First", Country = Countries[0] }, new Order() { Name = "Second", Country = Countries[1] }, new Order() { Name = "Third", Country = Countries[2] } }; protected override void OnInitialized() => selectedCountry = Countries[1]; } |
Vinatha,
This is not correct. I want to bind the Country object that is selected to Order.Country so that I get the correct country object set on the Order.
You "fixed" a bug recently to enable this:
This works when the autocomplete is NOT inside a Grid. But it is broken when the autocomplete is used inside a Grid.
Thanks,
| @using Syncfusion.Blazor.Grids @using Syncfusion.Blazor.DropDowns <SfGrid DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" TValue="Order"> <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings> <GridColumns> <GridColumn Field="Name" HeaderText="Name" Width="150"></GridColumn> <GridColumn Field="Country.Name" HeaderText="Country" Width="150"> <EditTemplate> @{ if (((context as Order).Country?.Code) == null) { (context as Order).Country = null; } } <SfAutoComplete TItem="Country" TValue="Country" ID="Id" @bind-value="@((context as Order).Country)" DataSource="Countries"> <AutoCompleteFieldSettings Text="Name" Value="Code"></AutoCompleteFieldSettings> </SfAutoComplete> </EditTemplate> </GridColumn> </GridColumns> </SfGrid> @code { private Country selectedCountry { get; set; } public class Country { public string Name { get; set; } public string Code { get; set; } } public static List<Country> Countries = new List<Country> { new Country() { Name = "Australia", Code = "AU" }, new Country() { Name = "Bermuda", Code = "BM" }, new Country() { Name = "Canada", Code = "CA" } }; public class Order { public string Name { get; set; } public Country Country { get; set; } } public List<Order> Orders = new List<Order>() { new Order() { Name = "First", Country = Countries[0] }, new Order() { Name = "Second", Country = Countries[1] }, new Order() { Name = "Third", Country = Countries[2] } }; protected override void OnInitialized() => selectedCountry = Countries[1]; } |