|
<EjsGrid AllowPaging="true" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridEvents OnActionBegin="Begin" TValue="Order"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
. . . . . . . . . . .. .
<GridColumn Field=@nameof(Order.OrderDate) EditType="EditType.DatePickerEdit" Format="dd/MM/yyyy" Type="ColumnType.Date" Width="120">
<EditTemplate>
<EjsDatePicker @ref="DatePicker" ID="OrderDate" Value="@((context as Order).OrderDate)" TValue="DateTime?" Format="dd/MM/yyyy" Width="120">
<DatePickerEvents TValue="DateTime?" ValueChange="FabricApprovedActualDateChange"></DatePickerEvents>
</EjsDatePicker>
</EditTemplate>
</GridColumn>
</GridColumns>
</EjsGrid>
@code{
EjsDatePicker<DateTime?> DatePicker { get; set; }
public List<Order> Orders { get; set; }
public void Begin(ActionEventArgs<Order> Args)
{
if(Args.RequestType == Syncfusion.EJ2.Blazor.Grids.Action.Save)
{
Args.Data.OrderDate = DatePicker.Value;
}
}
. . . . . .. . .
}
|
|
<SfGrid AllowPaging="true" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" EditType="EditType.NumericEdit" Format="C2" Width="140" TextAlign="@TextAlign.Right"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) EditType="EditType.DatePickerEdit" Format="dd/MM/yyyy" Type="ColumnType.Date" Width="120">
<EditTemplate>
<SfDatePicker ID="OrderDate" Value="@((context as Order).OrderDate)" TValue="DateTime?" Format="dd/MM/yyyy" Width="120">
<DatePickerEvents TValue="DateTime?" ValueChange="FabricApprovedActualDateChange"></DatePickerEvents>
</SfDatePicker>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
SfDatePicker<DateTime?> DatePicker { get; set; }
public List<Order> Orders { get; set; }
public class Order
{
public int? OrderID { get; set; }
public string CustomerID { get; set; }
[JsonConverter(typeof(CustomDateTimeConverter))]
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
class CustomDateTimeConverter : IsoDateTimeConverter
{
public CustomDateTimeConverter()
{
base.DateTimeFormat = "dd/MM/yyyy";
}
}
}
|
|
class CustomDateTimeConverter : IsoDateTimeConverter
{
public CustomDateTimeConverter()
{
base.DateTimeFormat = " MM/dd/yyyy ";
}
}
|
|
<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120">
<EditTemplate Context="context">
<SfDropDownList ID="CustomerID" Value="((context as Order).CustomerID)" TValue="string" TItem="string" DataSource="@customerList">
<DropDownListEvents TValue="string" ValueChange="OnCustomerChange"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" DefaultValue="@DefaultDate" Format="dd/MM/yyyy" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date">
<EditTemplate>
<SfDatePicker ID="OrderDate" Value="@((context as Order).OrderDate)" Enabled="@allowed" Format="dd/MM/yyyy" TValue="DateTime?"></SfDatePicker>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
. . . . . . .. . .
public void OnCustomerChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
allowed = true; // enable the datepicker component
}
}
|
Hi Preity,
Thanks for the update.
We are glad to hear that we have resolved your query.
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan
|
<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120">
<EditTemplate Context="context">
<SfDropDownList ID="CustomerID" @bind-Value="((context as Order).CustomerID)" TValue="string" TItem="string" DataSource="@customerList">
<DropDownListEvents TValue="string" ValueChange="OnCustomerChange"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" DefaultValue="@DefaultDate" Format="dd/MM/yyyy" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date">
<EditTemplate>
<SfDatePicker ID="OrderDate" @bind-Value="@((context as Order).OrderDate)" Enabled="@allowed" Format="dd/MM/yyyy" TValue="DateTime?"></SfDatePicker>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
|