|
<SfGrid AllowPaging="true" DataSource="@GridData" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">
<GridEvents OnActionBegin="OnActionBegin" TValue="OrdersDetails"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
. . .
<GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipCountry" Placeholder="Select a Country" TItem="string" TValue="string" DataSource="@Countries">
<DropDownListEvents TValue="string" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipCountry" Value="ShipCountry"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(OrdersDetails.ShipState) HeaderText=" ShipState" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipState" Placeholder="Select a State" TItem="string" Enabled="@Enabled" TValue="string" DataSource="@States">
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<OrdersDetails> GridData { get; set; }
public List<string> Countries = new List<string>() { "United States", "Australia" };
public List<string> States = new List<string>() { "New York", "Virginia", "Washington" };
public bool Enabled = false;
. . .
public void ValueChange(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
if (args.Value == "United States")
{
States = new List<string>() { "New York", "Virginia", "Washington" };
}
else if (args.Value == "Australia")
{
States = new List<string>() { "Queensland", "Tasmania", "Victoria" };
}
Enabled = true;
}
public void OnActionBegin(ActionEventArgs<OrdersDetails> args)
{
Enabled = false;
}
. . .
} |
|
<SfGrid AllowPaging="true" DataSource="@GridData" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">
<GridEvents OnActionBegin="OnActionBegin" TValue="OrdersDetails"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
. . .
<GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipCountry" Value="@((context as OrdersDetails).ShipCountry)" Placeholder="Select a Country" TItem="string" TValue="string" DataSource="@Countries">
<DropDownListEvents TValue="string" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipCountry" Value="ShipCountry"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(OrdersDetails.ShipState) HeaderText=" ShipState" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipState" Value="@((context as OrdersDetails).ShipState)" TItem="string" Enabled="@Enabled" TValue="string" DataSource="@States">
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid> |
|
<SfGrid AllowPaging="true" DataSource="@GridData" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">
<GridEvents OnActionBegin="OnActionBegin" TValue="Orders"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
. . .
<GridColumn Field=@nameof(Orders.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipCountry" Placeholder="Select a Country" TItem="string" TValue="string" @bind-Value="@((context as Orders).ShipCountry)" DataSource="@Countries">
<DropDownListEvents TItem="string" TValue="string" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipCountry" Value="ShipCountry"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Orders.ShipState) HeaderText=" ShipState" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipState" Placeholder="Select a State" TItem="string" Enabled="@Enabled" TValue="string" @bind-Value="@((context as Orders).ShipState)" DataSource="@States">
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid> |
|
<SfGrid @ref="Grid" AllowPaging="true" DataSource="@GridData" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">
<GridEvents OnActionBegin="OnActionBegin" OnActionComplete="ActionCompletedHandler" TValue="Orders"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Orders> Grid;
public List<Orders> GridData { get; set; } = new List<Orders>();
. . .
public bool Enabled { get; set; }
. . .
public void OnActionBegin(ActionEventArgs<Orders> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
Enabled = false;
Grid.PreventRender(false);
}
}
public void ActionCompletedHandler(ActionEventArgs<Orders> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
Grid.PreventRender(false);
}
}
} |