How to change selected row's color without click.

this is master-detatil grid.

after pageload, i did the mastergrid's first row select and show detail with out click.

now I do selected row's color change.

but i don't know how to change selected row's color.


below code is just example,  

Assume that the first row of the master grid is selected(without click) and the color does not change.

thanks

'''C#

@page "/Ex/EXS/ExPage07"

@using Syncfusion.Blazor.Layouts


@code{

    public aaa bbb { get; set; } = new();

}


<SfSplitter Height="100%" SeparatorSize="3" Orientation="Syncfusion.Blazor.Layouts.Orientation.Horizontal">

    <SplitterPanes>

        <SplitterPane Size="50%" Collapsible="true" CssClass="p-1">

            <ContentTemplate>

                <SfGrid ID="master" @onfocusin="@((e)=> bbb.grid_onfocusin(e,"master"))"

                DataSource="@Orders"

                GridLines="GridLine.Both" Width="100%"

                AllowSorting="false" AllowRowDragAndDrop="false" AllowGrouping="false">

                    <GridColumns>

                        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

                        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

                        <GridColumn 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>

            </ContentTemplate>

        </SplitterPane>

        <SplitterPane Size="50%" Collapsible="true" CssClass="p-1">

            <ContentTemplate>

                <SfGrid ID="detail" @onfocusin="@((e)=> bbb.grid_onfocusin(e,"detail"))"

                DataSource="@Orders"

                GridLines="GridLine.Both" Width="100%"

                AllowSorting="false" AllowRowDragAndDrop="false" AllowGrouping="false">

                    <GridColumns>

                        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

                        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

                        <GridColumn 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>

            </ContentTemplate>

        </SplitterPane>

    </SplitterPanes>

</SfSplitter>




@code {

    public List<Order> Orders { get; set; }



    public class aaa

    {

        public aaa()

        {


        }


        public string focusGrid { get; set; } = "";


        public void grid_onfocusin(Microsoft.AspNetCore.Components.Web.FocusEventArgs args, string name)

        {

            focusGrid = name;

            Console.WriteLine("focusGrid: " + focusGrid);

        }

    }


    protected override void OnInitialized()

    {

        Orders = Enumerable.Range(1, 75).Select(x => new Order()

            {

                OrderID = 1000 + x,

                CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

                Freight = 2.1 * x,

                OrderDate = DateTime.Now.AddDays(-x),

            }).ToList();

    }


    public class Order

    {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }

}


4 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team February 18, 2022 06:26 AM UTC

Hi Daehyun,  
 
Thanks for contacting Syncfusion support.  
 
Query: “Assume that the first row of the master grid is selected(without click) and the color does not change. 
 
We have prepared a sample using your code example and we found that first record of Master grid is not selected, hence its color is not changed. We suspect that you want to select a record in Grid without click. We suggest you to achieve your requirement SelectedRowIndex property of Grid.  
 
Refer the below code example  
 
<ContentTemplate> 
                <SfGrid ID="master" @onfocusin="@((e)=> bbb.grid_onfocusin(e,"master"))" 
                        DataSource="@Orders" SelectedRowIndex="0" 
                        GridLines="GridLine.Both" Width="100%" 
                        AllowSorting="false" AllowRowDragAndDrop="false" AllowGrouping="false"> 
. . . . ..  
                </SfGrid> 
            </ContentTemplate> 
 
We have a Master details sample in our online demo. Kindly refer the same for your reference 
 
 
Refer our API documentation for your reference 
 
 
Please get back to us if you have further queries or if we musunderstood your requirement.  
 
Regards, 
Vignesh Natarajan 



DK daehyun Kwon replied to Vignesh Natarajan February 18, 2022 12:33 PM UTC

sorry, I think my explanation wasn't enough.

my grid has combobox. so when first load page, it works. but after seleting combox to change data at grid, it's don't work



DK daehyun Kwon replied to Vignesh Natarajan February 21, 2022 09:42 AM UTC

SelectedRowIndex is rendered only at the beginning. But I select several grids with combo box and look them up. Therefore, SelectedRowIndex is applied only at first and not after. Is there a way to render a SelectedRowIndex every time the grid changes?



MS Monisha Saravanan Syncfusion Team February 21, 2022 01:09 PM UTC

Hi Daehyun, 

Thanks for your update 

We would like to inform that SelectRowIndex property will is used to select the record during the initial rendering only. So we suggest you to use SelectRowAsync method to select the DataGrid rows programmatically.  

If the above solution does not resolve your query, we need some more details about it as we are quite unclear about your exact requirement. So kindly share the following details.  

  1. Share us whether the combo box is placed inside/outside the grid.
  2. Share us the way you bind the datasource to the combo box.
  3. Share us the complete Grid code snippet.
  4. Share us the video demo explaining your query.
  5. If possible share us the simple issue reproducing sample

The above requested details will be helpful for us to validate your query and to provide you with a better solution as early as possible. 

Regards, 
Monisha 


Marked as answer
Loader.
Up arrow icon