<SfGrid @ref="@myGrid" DataSource="@Orders" @onkeyup="KeyUp" AllowPaging="true">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch" ShowConfirmDialog="false"></GridEditSettings>
<GridEvents TValue="Order" RowSelected="RowSelected"
CellSelected="CellSelectHandler"
OnCellEdit="OnCellEdit"
CellSaved="CellSaved"
QueryCellInfo="CustomizeCell"></GridEvents>
<GridSelectionSettings Mode="SelectionMode.Both"></GridSelectionSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120" IsPrimaryKey="true"></GridColumn>
<GridColumn AllowEditing="@CanOrderDate" Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public SfGrid<Order> myGrid { get; set; }
public bool CanOrderDate { get; set; } = true;
public bool CanOrderFreight { get; set; } = true;
public async Task CellSaved(CellSaveArgs<Order> args)
{
if (args.ColumnName == "CustomerID")
{
//find the row index
var rowIndex = await myGrid.GetRowIndexByPrimaryKey(args.RowData.OrderID);
//find the column index
var colIndex = myGrid.Columns.Select(x => x.Field).ToList().IndexOf("OrderID");
if (args.Value.ToString().ToLower() == "red")
{
await Runtime.InvokeVoidAsync("highlightcell", myGrid.ID, rowIndex, colIndex);
}
else
{
await Runtime.InvokeVoidAsync("removehighlight", myGrid.ID, rowIndex, colIndex);
}
}
CanOrderDate = false;
CanOrderFreight = false;
} |
Hi Marco,Thanks for contacting Syncfusion support.Query: “Our mail goal is to refresh the row UI data when we change the focus to the next cell to edit, without refreshing the entire datagrid view.”We have analyzed your query and we are understand you want to apply styles (background) UI to that particular column. We have achieve your requirement by calling a JavaScript function in CellSaved event by passing the row and column index. In the JavaScript method, based on row and column index. We have applied styles to that column.Refer the below code example.
<SfGrid @ref="@myGrid" DataSource="@Orders" @onkeyup="KeyUp" AllowPaging="true"><GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch" ShowConfirmDialog="false"></GridEditSettings><GridEvents TValue="Order" RowSelected="RowSelected"CellSelected="CellSelectHandler"OnCellEdit="OnCellEdit"CellSaved="CellSaved"QueryCellInfo="CustomizeCell"></GridEvents><GridSelectionSettings Mode="SelectionMode.Both"></GridSelectionSettings><GridColumns><GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120" IsPrimaryKey="true"></GridColumn><GridColumn AllowEditing="@CanOrderDate" Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn><GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn></GridColumns></SfGrid>@code{public List<Order> Orders { get; set; }public SfGrid<Order> myGrid { get; set; }public bool CanOrderDate { get; set; } = true;public bool CanOrderFreight { get; set; } = true;public async Task CellSaved(CellSaveArgs<Order> args){if (args.ColumnName == "CustomerID"){//find the row indexvar rowIndex = await myGrid.GetRowIndexByPrimaryKey(args.RowData.OrderID);//find the column indexvar colIndex = myGrid.Columns.Select(x => x.Field).ToList().IndexOf("OrderID");if (args.Value.ToString().ToLower() == "red"){await Runtime.InvokeVoidAsync("highlightcell", myGrid.ID, rowIndex, colIndex);}else{await Runtime.InvokeVoidAsync("removehighlight", myGrid.ID, rowIndex, colIndex);}}CanOrderDate = false;CanOrderFreight = false;}[javascript.js]
function highlightcell(gridId, row, col) { document.getElementById(gridId + "_content_table").querySelectorAll("tr.e-row")[row].querySelectorAll("td")[col].style.background = "red"; } function removehighlight(gridId, row, col) { document.getElementById(gridId + "_content_table").querySelectorAll("tr.e-row")[row].querySelectorAll("td")[col].style.background = ""; } [host.cshtml]
<head> <meta charset="utf-8" /> <link rel='nofollow' href="_content/Syncfusion.Blazor/styles/material.css" rel="stylesheet" /> <script src="~/JavaScript.js"></script> </head> Kindly download the sample from belowPlease get back to us with more details if you have further queries.Regards,Vignesh Natarajan
public async Task CellSaved(CellSaveArgs<Order> args)
{
if (args.ColumnName == "CustomerID")
{
//find the row index
var rowIndex = await myGrid.GetRowIndexByPrimaryKey(args.RowData.OrderID);
. . . . . .
//update the other columns without change the dom or refreshing
await myGrid.UpdateCell(rowIndex, "OrderDate", DateTime.Now);
await myGrid.UpdateCell(rowIndex, "Freight", (double)99);
}
CanOrderDate = false;
CanOrderFreight = false;
}
|