If its possible to have default value from in SfGrid with dropdown list?
In this example:
<GridColumn Field="TTYPE.TicketType" HeaderText="Type"
Width="120" AllowResizing=false ValidationRules="@(new ValidationRules{ Required= true})"
FilterSettings="@(new FilterSettings() {Type=Syncfusion.Blazor.Grids.FilterType.CheckBox})">
<EditTemplate>
<SfDropDownList DataSource="@TTYPEs" TItem="TTYPE" TValue="TTYPE" @bind-Value="@((context as TWO).TTYPE)">
<DropDownListFieldSettings Text="TicketType" Value="TtypeID"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
Thank you,
Hi Artem,
Greetings from Syncfusion.
We have prepared an simple sample as per your shared reference. Kindly check the below attached sample and code snippet for your reference.
Here we have used value property of DropdownList and assigned the default value in the ActionBegin event. By using the ValueChange event we have updated the changed value to the DataGrid.
|
<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315"> <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> <GridEvents OnActionBegin="ActionBegin" TValue="Order"></GridEvents> <GridColumns>
<GridColumn Field="@nameof(Order.ShipCountry)" HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150"> <EditTemplate> @{ var data = (context as Order); } <SfDropDownList ID="ShipCountry" TItem="Country" TValue="string" Value="@val" DataSource="@Countries"> <DropDownListFieldSettings Value="CountryName" Text="CountryName"></DropDownListFieldSettings> <DropDownListEvents ValueChange="@(args =>ValueChange(args,data))" TItem="Country" TValue="string"></DropDownListEvents> </SfDropDownList> </EditTemplate> </GridColumn> </GridColumns> </SfGrid>
@code { public List<Order> Orders { get; set; } public string val { get; set; } public void ActionBegin(Syncfusion.Blazor.Grids.ActionEventArgs<Order> args) { if((args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.BeginEdit)) || (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Add))) { val = Countries[2].CountryName; } } public void ValueChange(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, Country> args, Order data) { data.ShipCountry = args.Value.ToString(); }
} |
Please let us know if you have any concerns.
Regards,
Monisha