|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.CanEdit) HeaderText="Customer Name" Width="150">
<EditTemplate>
<SfDropDownList ID="CanEdit" TItem="string" TValue="string" @bind-Value="@((context as Order).CanEdit)" DataSource="@Cust">
<DropDownListEvents ValueChange="OnChange" TItem="string" TValue="string"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
<SfDialog Width="250px" ShowCloseIcon="true" IsModal="true" @bind-Visible="@IsVisible">
<DialogTemplates>
<Content> Are you sure you want to disable the editing </Content>
</DialogTemplates>
<DialogButtons>
<DialogButton Content="OK" IsPrimary="true" OnClick="@CloseDialog" />
</DialogButtons>
</SfDialog>
@code{
SfGrid<Order> Grid { get; set; }
public List<Order> Orders { get; set; }
public List<string> Cust = new List<string>() { "A", "B", "C" };
private void CloseDialog()
{
this.IsVisible = false; // to clse the confirmation dialog.
Grid.CloseEdit(); // to cancel the editing in Grid
}
public void OnChange(ChangeEventArgs<string, string> Args)
{
if(Args.Value == "C")
{
IsVisible = true; // to show the confirmation dialog.
}
}
private bool IsVisible { get; set; } = false; |
public void OnActionBegin(ActionEventArgs<Order> args)
{
if(args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.BeginEdit) && args.Data.CanEdit == "C")
{
args.Cancel = true;
}
if(args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save) && args.Data.CanEdit == "C")
{
IsVisible = true;
}
}
|
|
public void Save()
{
Grid.CloseEdit(); // to close the editform
IsVisible = true;
}
|
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
. .
<GridColumns>
<GridColumn Field=@nameof(Order.CanEdit) HeaderText="Customer Name" Width="150">
<EditTemplate>
<SfDropDownList @ref="DDL" ID="CanEdit" TItem="string" TValue="string" @bind-Value="@((context as Order).CanEdit)" DataSource="@Cust">
</SfDropDownList>
</EditTemplate>
</GridColumn>
…. .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public List<Order> Orders { get; set; }
public Order CurrentEditedRecd { get; set; }
SfDropDownList<string, string> DDL { get; set; }
public List<string> Cust = new List<string>() { "A", "B", "C" };
public void Close()
{
Grid.CloseEdit(); // to cancel the editing
}
public void Save()
{
if (DDL.Value == "C")
{
Grid.CloseEdit(); // to close the edit form
IsVisible = true; // to display the confirmation dialog
}
else
{
Grid.EndEdit(); // to save the changes in grid when value is A or B
}
}
|