|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Both"></GridSelectionSettings>
<GridEvents CellSelected="CellSelectHandler" OnActionComplete="OnComplete" TValue="Order"></GridEvents>
. . . . .. . . .
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public int CurrentEditCellIndex = 0;
public List<Order> Orders { get; set; }
public async Task OnComplete(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
var Fields = await Grid.GetColumnFieldNames();
await Runtime.InvokeVoidAsync("focus", Grid.ID, Fields[CurrentEditCellIndex]); // to call a JS fucnction to focus the cell
}
}
public async void CellSelectHandler(CellSelectEventArgs<Order> args)
{
var EditCellIndex = JsonConvert.DeserializeObject<Dictionary<string, object>>(args.CellIndex.ToString());
foreach (var key in EditCellIndex)
{
if (key.Key == "cellIndex")
{
CurrentEditCellIndex = Convert.ToInt32(key.Value); // to find the CellIndex
}
}
}
Focusing.js
|
|
<SfGrid @ref="Grid" 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>
<GridSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Both"></GridSelectionSettings>
<GridEvents CellSelected="CellSelectHandler" OnActionComplete="OnComplete" TValue="Order"></GridEvents>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public double CurrentEditCellIndex = 0;
SfGrid<Order> Grid { get; set; }
public async Task OnComplete(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
var Fields = await Grid.GetColumnFieldNames(); // return list of fields in cell
await Runtime.InvokeVoidAsync("focus", Grid.ID, Fields[(int)CurrentEditCellIndex]); // to call a JS fucnction to focus the cell
}
}
public async Task CellSelectHandler(CellSelectEventArgs<Order> args)
{
CurrentEditCellIndex = args.CellIndex; // get the cell index
}
. . . . . |