Hi,
I'm having a Grid in Batch Mode. When I single click on a Checkbox cell, I can trigger the single click edit successfully. Unfortunatly, I have to select another cell or row so the Grid recognizes the change and the default 'Update' button is activated.
Is there a way to activate the button directly after any change without clicking on another cell? Huge thanks in advance!
Here is the code I'm using:
<SfGrid TValue="UserEditModel" DataSource="_userEditModels" @ref="_userDataGrid" AllowSorting="true" AllowSelection="true" AllowReordering="false" AllowExcelExport="true" Toolbar="_toolBarItemsUserGrid">
<GridSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Both"></GridSelectionSettings>
<GridPageSettings PageSize="4"></GridPageSettings>
<GridEvents OnBatchSave="UserGridOnBatchSaveHandler" CellSelected="UserGridCellSelectHandler" QueryCellInfo="UserGridCustomizeCell" OnToolbarClick="UserGridToolbarClickHandler" TValue="UserEditModel"></GridEvents>
<GridEditSettings AllowEditing="true" Mode="EditMode.Batch" ShowConfirmDialog="false"></GridEditSettings>
<GridColumns>
<GridColumn Field="@nameof(UserEditModel.Id)" HeaderText="Id" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Left" AutoFit=true AllowEditing="false" IsPrimaryKey="true" Visible="false"></GridColumn>
<GridColumn Field="@nameof(UserEditModel.Email)" HeaderText="@_localizer["UserDetail_User_Grid_Email"]" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Left" AutoFit=true AllowEditing="false"></GridColumn>
<GridColumn Field="@nameof(UserEditModel.LastName)" HeaderText="@_localizer["UserDetail_User_Grid_LastName"]" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" AutoFit=true AllowEditing="false"></GridColumn>
<GridColumn Field="@nameof(UserEditModel.FirstName)" HeaderText="@_localizer["UserDetail_User_Grid_FirstName"]" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" AutoFit=true AllowEditing="false"></GridColumn>
<GridColumn Field="@nameof(UserEditModel.Location)" HeaderText="@_localizer["UserDetail_User_Grid_Location"]" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" AutoFit=true AllowEditing="false"></GridColumn>
<GridColumn Field="@nameof(UserEditModel.IsBillable)" HeaderText="@_localizer["UserDetail_User_Grid_IsBillable"]" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" DisplayAsCheckBox="true" AllowEditing="true"></GridColumn>
<GridColumn Field="@nameof(UserEditModel.UserType)" HeaderText="@_localizer["UserType"]" EditType="EditType.DropDownEdit" Width="150" AllowEditing="true">
<EditTemplate>
<SfDropDownList ID="UserUserTypeName" TItem="UserTypeModel" TValue="string" @bind-Value="@((context as UserEditModel).UserType)" DataSource="@_userTypes">
<DropDownListFieldSettings Value="Name" Text="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
// copy paste from: https://blazor.syncfusion.com/documentation/datagrid/how-to/single-click-editing-with-batch-mode
public async Task UserGridCellSelectHandler(CellSelectEventArgs<UserEditModel> args)
{
//get selected cell index
var cellIndexes = await _userDataGrid.GetSelectedRowCellIndexes();
//get the row and cell index
var currentEditRowIndex = cellIndexes[0].Item1;
var currentEditCellIndex = (int)cellIndexes[0].Item2;
//get the available fields
var fields = await _userDataGrid.GetColumnFieldNames();
// edit the selected cell using the cell index and column name
await _userDataGrid.EditCell(currentEditRowIndex, fields[currentEditCellIndex]);
}
// nothing special here
private async Task UserGridToolbarClickHandler(ClickEventArgs args)
{
if (args.Item.Id == $"{_userDataGrid.ID}_excelexport")
{
var excelProperties = new ExcelExportProperties();
excelProperties.FileName = $"{DateTime.Now:yyyyMMddHHmmss}_UserExport_{_customer.Name.Replace(" ", "-")}.xlsx";
await _userDataGrid.ExcelExport(excelProperties);
}
}
// nothing special here
private async Task UserGridOnBatchSaveHandler(BeforeBatchSaveArgs<UserEditModel> args)
{
var changedModels = args.BatchChanges.ChangedRecords;
await _userService.UpdateUsers(changedModels);
_userEditModels = await _userService.RefreshUsers();
}
// nothing special here
private void UserGridCustomizeCell(QueryCellInfoEventArgs<UserEditModel> args)
{
if (args.Column.Field != nameof(UserEditModel.UserType))
return;
switch (args.Data.UserType)
{
case "1":
args.Cell.AddClass(new[] { "usertype-1" });
break;
case "2":
args.Cell.AddClass(new[] { "usertype-2" });
break;
case "3":
args.Cell.AddClass(new[] { "usertype-3" });
break;
}
}
Hello and thank you for this hint. Unfortunately this is not why I need.
When I change something, I want it directly being recognized as a change on my record with all related actions on the Grid. With the solution you provided in your link, when I click on the CheckBox, the OnCellEdit event is fired, but it should be fired when I just edited a value, not before or when activating the Edit Mode.
Further, the OnCellEdit event will then be fired again when clicking on another cell. Then the changed cell is also highlighted and the Update button is activated - same behavior as without using the OnCellEdit event.
I attached the following gif for a better understanding:
Steps I made to create that scenario on the image:
Nice, that's exactly what I need. Thanks a lot for your great and super fast support!