|
<SfDialog Width="250px" ShowCloseIcon="true" IsModal="true" @bind-Visible="@IsVisible"> // rendering the dialog while clicking other rows while editing
<DialogTemplates>
<Header> Confirmation </Header>
<Content> Do you want to save this record? </Content>
</DialogTemplates>
<DialogButtons>
<DialogButton Content="Save" IsPrimary="true" OnClick="@EndDialog" />
<DialogButton Content="Cancel" OnClick="@CancelDialog" />
</DialogButtons>
</SfDialog>
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() {"Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="ActionBegin" TValue="Order" OnRecordClick="RecordClickHandler"
OnToolbarClick="ToolbarClickHandler"></GridEvents>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
private bool PreventUpdate { get; set; } //introducing Boolean value to achieve the requirement
private bool IsVisible { get; set; } //for dialog showing and hiding
public bool IsAdd { get; set; }
. . .
private void ActionBegin(ActionEventArgs<Order> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save && PreventUpdate)
{
args.Cancel = true;
OpenDialog();
}
}
public void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Text == "Update")
{
PreventUpdate = false;
}
}
public void RecordClickHandler(RecordClickEventArgs<Order> args)
{
PreventUpdate = true;
}
private void OpenDialog()
{
this.IsVisible = true;
}
private void EndDialog()
{
this.IsVisible = false;
PreventUpdate = false;
if (IsAdd)
{
Grid.CloseEdit();
IsAdd = false;
} else
{
Grid.EndEdit();
}
}
private void CancelDialog()
{
this.IsVisible = false;
PreventUpdate = false;
Grid.CloseEdit();
}
. . .
} |