|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>
<GridEvents OnCellSave="CellSavedHandler" OnCellEdit="CellEditHandler" TValue="Order"></GridEvents>
<GridColumns>
. . .
<GridColumn Field=@nameof(Order.Quantity) HeaderText="Quantity" EditType="EditType.DropDownEdit" TextAlign="TextAlign.Right" Width="120">
<EditTemplate>
<SfDropDownList @ref="Dropdown" ID="Quantity" TValue="int?" TItem="Games" @bind-Value="@((context as Order).Quantity)" Placeholder="Select Quantity" DataSource="@LocalData">
<DropDownListFieldSettings Value="ID" Text="ID"></DropDownListFieldSettings>
<DropDownListEvents Created="Created" TValue="int?" TItem="Games" ValueChange="OnValueChangeForCol6" />
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
SfDropDownList<int?, Games> Dropdown;
. . .
public double IndexValue { get; set; }
public void CellSavedHandler(CellSaveArgs<Order> args)
{
if (args.ColumnName == "Quantity")
{
args.Value = Dropdown.Value;
}
}
public void Created()
{
Grid.PreventRender(false);
}
public async Task CellEditHandler(CellEditArgs<Order> args)
{
IndexValue = await Grid.GetRowIndexByPrimaryKey(args.RowData.OrderID); //get Index value
}
private async Task OnValueChangeForCol6(Syncfusion.Blazor.DropDowns.ChangeEventArgs<int?, Games> args)
{
var Value = (new string[] { "USA", "UK", "CHINA", "RUSSIA", "INDIA" })[new Random().Next(5)];
await Grid.UpdateCell(IndexValue, "ShipCountry", Value); //updated ShipCountry value in dropdown change
}
} |
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>
<GridEvents OnCellSave="CellSavedHandler" OnCellEdit="CellEditHandler" TValue="Order"></GridEvents>
<GridColumns>
. . .
<EditTemplate>
<SfComboBox @ref="ComboBox" ID="Quantity" TValue="int?" TItem="Games" @bind-Value="@((context as Order).Quantity)" DataSource="@LocalData">
<ComboBoxFieldSettings Value="ID" Text="ID"></ComboBoxFieldSettings>
<ComboBoxEvents Created="Created" TValue="int?" TItem="Games" ValueChange="OnValueChangeForCol6"></ComboBoxEvents>
</SfComboBox>
</EditTemplate>
</GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
SfDropDownList<int?, Games> Dropdown;
SfDropDownList<int?, Games> ComboBox;
public List<Order> Orders { get; set; }
. . .
public double IndexValue { get; set; }
public void CellSavedHandler(CellSaveArgs<Order> args)
{
if (args.ColumnName == "Quantity")
{
args.Value = ComboBox.Value;
}
}
public void Created()
{
Grid.PreventRender(false);
}
public async Task CellEditHandler(CellEditArgs<Order> args)
{
IndexValue = await Grid.GetRowIndexByPrimaryKey(args.RowData.OrderID);
}
private async Task OnValueChangeForCol6(Syncfusion.Blazor.DropDowns.ChangeEventArgs<int?, Games> args)
{
var Value = (new string[] { "USA", "UK", "CHINA", "RUSSIA", "INDIA" })[new Random().Next(5)];
await Grid.UpdateCell(IndexValue, "ShipCountry", Value);
}
} |
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>
<GridEvents OnCellSave="CellSavedHandler" OnCellEdit="CellEditHandler" TValue="Order"></GridEvents>
<GridColumns>
. . .
<GridColumn Field=@nameof(Order.Quantity) HeaderText="Quantity" EditType="EditType.DropDownEdit" TextAlign="TextAlign.Right" Width="120">
<EditTemplate>
<SfComboBox @ref="ComboBox" ID="Quantity" TValue="int?" TItem="Games" @bind-Value="@((context as Order).Quantity)" DataSource="@LocalData">
<ComboBoxFieldSettings Value="ID" Text="ID"></ComboBoxFieldSettings>
<ComboBoxEvents Created="Created" TValue="int?" TItem="Games" ValueChange="OnValueChangeForCol6"></ComboBoxEvents>
</SfComboBox>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
. . .
public List<Order> Orders { get; set; }
. . .
private async Task OnValueChangeForCol6(Syncfusion.Blazor.DropDowns.ChangeEventArgs<int?, Games> args)
{
var Value = (new string[] { "USA", "UK", "CHINA", "RUSSIA", "INDIA" })[new Random().Next(5)];
if(args.Value != null) // you can resolve by adding this condition
{
await Grid.UpdateCell(IndexValue, "ShipCountry", Value);
}
}
} |