<SfGrid ID="Grid" @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" AllowNextRowEdit="true" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" ValidationRules="@(new ValidationRules { Required = true })" Type="ColumnType.Number" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" ValidationRules="@(new ValidationRules{ Required=true})" Width="120">
<EditTemplate>
<SfTextBox ID="CustomerID" @onkeydown="Keydo" @bind-Value="@((context as Order).CustomerID)"></SfTextBox>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" AllowEditing="false" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
@code{
SfGrid<Order> Grid { get; set; }
public List<Order> Orders { get; set; }
public async void Keydo(KeyboardEventArgs Args)
{
if (Args.Code == "Tab")
{
var selectedIndex = await Grid.GetSelectedRowIndexes();
await Grid.EditCell(selectedIndex[0], Grid.Columns[3].Field);
}
}
} |
If there another way to skip non-editable columns in batch mode? I have a grid with many columns and all of them are set to AllowEditing="false" except for two columns which are editable. I want the batch edit focus to move to the next editable column (perhaps in the next row) when Tab is pressed.
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Inputs
<SfGrid ID="Grid" @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" AllowNextRowEdit="true" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" ValidationRules="@(new ValidationRules { Required = true })" Type="ColumnType.Number" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" ValidationRules="@(new ValidationRules{ Required=true})" Width="120">
<EditTemplate>
<SfTextBox ID="CustomerID" @onkeydown="@(e=>Keydo(e, (context as Order)))" @bind-Value="@((context as Order).CustomerID)"></SfTextBox>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" AllowEditing="false" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" EditType="EditType.NumericEdit" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
@{
<SfTextBox ID="ShipCountry" @onkeydown="@(e=>ShipCountryKeydown(e, (context as Order)))" @bind-Value="@((context as Order).ShipCountry)"></SfTextBox>
}
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public List<Order> Orders { get; set; }
public async void Keydo(KeyboardEventArgs Args, Order order)
{
if (Args.Code == "Tab")
{
var index = await Grid.GetRowIndexByPrimaryKey(order.OrderID);
await Grid.EditCell(index, Grid.Columns[3].Field);
}
}
public async void ShipCountryKeydown(KeyboardEventArgs Args, Order order)
{
if (Args.Code == "Tab")
{
var index = await Grid.GetRowIndexByPrimaryKey(order.OrderID);
await Grid.EditCell(index +1, Grid.Columns[1].Field);
}
}
|