<SfGrid TValue="ExpandoObject" AllowSorting="true" DataSource="Orders" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" , "Search" })">
<GridEvents OnActionBegin="ActionBeginHandler" TValue="ExpandoObject"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field="Customer_ID" HeaderText="Customer Name" Width="120">
<EditTemplate>
<SfTextBox Multiline="true" ShowClearButton="true" Input="TextInput" ID="Customer_ID" CssClass="grid-font"
Value="@((string)(context as IDictionary<string, object>)["Customer_ID"])" />
</EditTemplate>
</GridColumn>
<GridColumn Field="OrderDate" HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
<GridColumn Field="Freight" HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" EditType="EditType.NumericEdit" Width="120"></GridColumn>
<GridColumn Field="Verified" HeaderText="Active" EditType="EditType.BooleanEdit" DisplayAsCheckBox="true" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public static List<ExpandoObject> Orders { get; set; } = new List<ExpandoObject>();
public string TextValue { get; set; } = "";
public void TextInput(InputEventArgs Args)
{
TextValue = Args.Value; //update the public variable on typing the value in textbox
}
public void ActionBeginHandler(ActionEventArgs<ExpandoObject> Args)
{
if(Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
var data = Args.Data as IDictionary<string, object>;
data["Customer_ID"] = TextValue; // udpate the public variable value on saving the record
}
}
}
|