Hi Alessandro,
Query 1 : when the socus i set to this cell I would like to become editable.
By default, pressing tab key from one cell will place the focus to immediate next cell. In this case, when the current cell is in edited state then pressing tab will make the next cell also editable. But, if the current cell is not in edited state then it will just set the focus to next cell and won’t make that next cell editable. This is the default behavior of pressing Tab in Grid and this is why the reported behavior occurred.
We have prepared a sample to overcome this default behavior and achieve your requirement. (i.e.) achieve single click editing when pressing tab key based on your scenario. Please download the sample from the link below,
In the above sample, we have used @onkeyup, RowSelected, CellSelected and OnCellEdit events to Grid to achieve this requirement. We have used the RowSelected and OnCellEdit event handlers to fetch the required row and cell indexes. And in CellSelected and @onkeuup handlers we handle the logic to edit the required cell on single click or tab way of selecting the cell.
Please refer the below codes with explanations for more details,
<SfGrid @ref="@myGrid" DataSource="@Orders" @onkeyup="KeyUp" AllowPaging="true"> <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings> <GridEvents TValue="Order" RowSelected="RowSelected" CellSelected="CellSelectHandler" OnCellEdit="OnCellEdit" CellSaved="CellSaved"></GridEvents> <GridSelectionSettings Mode="SelectionMode.Both"></GridSelectionSettings> ...</SfGrid> @code{ public List<Order> Orders { get; set; } public SfGrid<Order> myGrid { get; set; } ... public async Task KeyUp(KeyboardEventArgs Args) { if (Args.Key == "Tab") { var a = await myGrid.GetSelectedRowCellIndexes(); var cols = await myGrid.GetColumns(); if (a.Count == 0) { //use the row and cell index values to select the row and edit the cell await myGrid.SelectRow(CurrentEditRowIndex); await myGrid.EditCell(CurrentEditRowIndex, cols[Convert.ToInt32(CurrentEditCellIndex + 1)].Field); } } } public int CurrentEditCellIndex; public double CurrentEditRowIndex; public async Task RowSelected(RowSelectEventArgs<Order> args) { //update the row and cell index values if(CurrentEditRowIndex != args.RowIndex) { CurrentEditRowIndex = args.RowIndex; CurrentEditCellIndex = 0; } } public async Task CellSelectHandler(CellSelectEventArgs<Order> args) { //this will have same codes as in single click batch edit documentation } public async Task OnCellEdit(CellEditArgs<Order> args) { //update the row and cell index values here using GetColumnIndexByField and GetRowIndexByPrimaryKey methods CurrentEditCellIndex = (int)await myGrid.GetColumnIndexByField(args.ColumnName); CurrentEditRowIndex = await myGrid.GetRowIndexByPrimaryKey(args.RowData.OrderID); if (!CanOrderDate) { if (args.ColumnName == "OrderDate") args.Cancel = true; } ... } ...}
|
Reference :
Query 2 : In order to make a cell editable or not based on the values of the row.
We suggest you to use the OnCellEdit event of Grid. In this event handler based on args.RowData value you can compare current editable cell’s value and set args.Cancel to prevent editing for that particular valued cell. Please refer the codes below. We have also included the below code in above attached sample(Freight column cell with 4.2 as value will not be editable)
public async Task OnCellEdit(CellEditArgs<Order> args){ ... if(args.ColumnName == "Freight" && args.RowData.Freight == 4.2) { args.Cancel = true; //cancel the cell editing based on cell value in args.RowData }}
|
Query 3 : but i need to move to the "next index Columns", like a tab index in control forms.
We suggest you to bind @onkeyup event to Grid. In this event handler you can call the EditCell method to make any cell in Grid editable instead of the next cell, when pressing the Tab key.
| <SfGrid @ref="@myGrid" DataSource="@Orders" @onkeyup="KeyUp" AllowPaging="true"> ...</SfGrid>
public async Task KeyUp(KeyboardEventArgs Args)
{
if (Args.Key == "Tab")
{
//based on current selected cell value or rowdata value you can call the EditCell to enable editing for a cell other than the next cell
await myGrid.EditCell(1, "Freight"); //Pass your cell’s row index and column name as argument for EditCell
}
}
|
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran