<SfGrid TValue="Projet_General" DataSource="projets"
Toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Cancel", "Update", "Excel Export", "PDF Export"})"
AllowExcelExport="true"
AllowPdfExport="true">
<GridEvents RowSelected="OnSelectedRowChanged" TValue="Projet_General" OnToolbarClick="TypologieToolbarClick"/>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog"/>
<GridColumns>
<GridColumn Field="@nameof(Projet_General.Id)" IsPrimaryKey="true" Visible="false"></GridColumn>
<GridColumn Field="@nameof(Projet_General.Name)"></GridColumn>
<GridColumn Field="@nameof(Projet_General.Description)"></GridColumn>
<GridColumn Field="@nameof(Projet_General.SuperficieTerrain)"></GridColumn>
</GridColumns>
</SfGrid>
Ex:protected void Add(Projet_General projetGeneral)
{
_unitOfWork.ProjetGeneral.Add(projetGeneral);
_unitOfWork.Save();
}protected void Update(Projet_General projetGeneral)
{
_unitOfWork.ProjetGeneral.Update(projetGeneral);
_unitOfWork.Save();
}protected void Remove(Projet_General projetGeneral)
{
_unitOfWork.ProjetGeneral.Remove(projetGeneral);
_unitOfWork.Save();
}
protected async Task ActionCompleted(ActionEventArgs<Projet_General> arg)
{
if (arg.RequestType == Action.Delete)
{
_unitOfWork.ProjetGeneral.Remove(arg.Data);
await _unitOfWork.Save();
}
if (arg.Action == null)
return;
if (arg.Action == "Add")
_unitOfWork.ProjetGeneral.Add(arg.Data);
else if (arg.Action == "Edit")
await _unitOfWork.ProjetGeneral.UpdateAsync(arg.Data);
await _unitOfWork.Save();
}
<SfGrid @ref="Grid" DataSource="@GridData" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })" AllowFiltering="true" AllowSorting="true" AllowPaging="true">
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings>
<GridEvents OnActionBegin="OnBegin" OnActionComplete="OnComplete" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" Visible="false" IsIdentity="true" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public IEnumerable<Order> GridData { get; set; }
protected override void OnInitialized()
{
GridData = OrderData.GetAllOrders().ToList();
}
public void OnComplete(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save || Args.RequestType == Syncfusion.Blazor.Grids.Action.Cancel)
{
// fetch updated data from service and bind to grid datasource property
GridData = OrderData.GetAllOrders().ToList();
}
}
public void OnBegin(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save) // update the changes in Actionbegine event
{
if (Args.Action == "Add")
{
//insert the record into database
OrderData.AddOrder(Args.Data);
}
else
{
//update the existing record
OrderData.UpdateOrder(Args.Data);
}
}
else if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Delete)
{
// delete the record from your database
OrderData.DeleteOrder(Args.Data.OrderID);
}
}
|