Change Row backcolor when a specific column is updated

Hello team,


I am working on a Blazor datagrid requirement where, when the user updates a specific column the backcolor of the row belonging to the cell being updated should be changed dynamically.


For eg: I have the below grid. When the user edits the cell value of the OrderDate column and updates the database by hitting on update button on the toolbar i want to change the backcolor of the row to say green or blue.

Currently the Edit mode of the grid is Normal. For your reference the Datagrid in Razor component as below.

<SfGrid DataSource="@SalesOrdersList" AllowPaging="true" AllowSorting="true" AllowGrouping="true" ID="SalesGrid" GridLines="GridLine.Both"  AllowFiltering="true" @ref="salesOrdersGrid" AllowTextWrap="true" AllowExcelExport="true" AllowPdfExport="true" PrintMode=PrintMode.CurrentPage Toolbar="@(new List<string>() { "Add", "Edit", "Update", "Delete", "Cancel","Search", "Print", "PdfExport", "ExcelExport" })" Height="100%" Width="100%">

        <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" />

        <GridEvents OnActionBegin="@ActionBeginHandler" TValue="@SalesOrders"            OnToolbarClick="ToolbarClickHandler"  QueryCellInfo="CustomizeCell" ></GridEvents>

              <GridColumns>

            <GridColumn IsPrimaryKey="true" Field=@nameof(SalesOrders.SalesOrdersID) HeaderText="ID" Width="40px" Visible="false" AllowAdding="false"> </GridColumn>

            <GridColumn Field=@nameof(SalesOrders.WorkCenter) HeaderText="Work Center" Width="150px"></GridColumn>

            <GridColumn Field=@nameof(SalesOrders.FW) HeaderText="FW" Width="100px"></GridColumn>

            <GridColumn Field=@nameof(SalesOrders.OrderDate) HeaderText="Order Date" Width="150px" DefaultValue="@(DateTime.Now)"

                        EditType="EditType.DateTimePickerEdit" Format="d" Type="ColumnType.Date"></GridColumn>

            <GridColumn Field=@nameof(SalesOrders.SalesOrderNumber) HeaderText="Sales Order Number" Width="150px">

            </GridColumn>

</GridColumns>

    </SfGrid>



Thanks

Baba


3 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team February 11, 2022 09:29 AM UTC

Hi Baba, 
 
Greetings from Syncfusion support. 
 
Query : i want to change the backcolor of the row to say green or blue. 
We have bind the OnActionBegin event. In this event handler based on the RequestType as Save we have stored the primary key column value to a List. Now use this stored List value for applying the styles inside RowDataBound event handler. 
 
We have also prepared a sample based on your requirement. Please download the sample from the link below, 
References :  
 
 
<GridEvents OnActionBegin="OnActionBegin" RowDataBound="RowDataBound" TValue="Order"></GridEvents> 
 
    public void OnActionBegin(ActionEventArgs<Order> args) 
    { 
        if (args.RequestType.Equals(Action.Save) && args.Action == "Edit") 
        { 
            //store the primary key on save 
            EditedCells.Add(args.Data.OrderID); 
        } 
    } 
    public void RowDataBound(RowDataBoundEventArgs<Order> args) 
    { 
        //check based on stored list and apply style for corresponding edited row 
        if (EditedCells.Count != 0) 
        { 
            if (EditedCells.Contains(args.Data.OrderID)) 
            { 
                    args.Row.AddClass(new string[] { "editedcellcss" });                     
            } 
        } 
    } 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 


Marked as answer

BG Baba Goud February 15, 2022 10:45 AM UTC

Hello Renjith,


Appreciate for providing a quick reply, the above code worked as expected, thank you!


Thanks,

Baba



RS Renjith Singh Rajendran Syncfusion Team February 16, 2022 05:01 AM UTC

Hi Baba, 
 
Thanks for your update. Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 


Loader.
Up arrow icon