Hi Preity,
Thanks for contacting Syncfusion support.
Query: “When I add a new record I want to populate a default datetime (which is datetime.now + 14 days) for this column and I want it editable”
We suggest you to achieve your requirement using DefaultValue property of the GridColumn. Refer the below code example
|
<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.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 bool allowed = false;
public DateTime? DefaultDate = DateTime.Now.AddDays(+14);
. .. . .
}
|
For your convenience we have attached the sample which can be downloaded from below
Note: DatePicker will be disabled state, it will be enabled once you select a value from CustomerID column dropdownlist. If you want to enable DatePicker on initial rendering. Kindly remove the Enabled property from SfDatePicker. We have provided this solution based on sample provided in F152607
Refer our UG documentation for your reference
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan