【问题标题】:Datagrid - how to change background color of a row based on a condiitonDatagrid - 如何根据条件更改行的背景颜色
【发布时间】:2023-01-16 12:26:17
【问题描述】:

在我的 Blazor 服务器应用程序中,我试图根据以下条件更改数据网格行的背景颜色;

void RowRender(RowRenderEventArgs<Order> args)
{
    if(args.Data.Status == "Completed")
        args.Attributes.Add("style", "background-color: var(--rz-success-light)");
} 

但是如果我点击该行它会改变颜色。如何在不选择行的情况下使其工作?

    <RadzenDataGrid @ref="_grid" AllowFiltering="true" AllowPaging="true" PageSize="7" AllowSorting="true" RowClick="RowClick" ExpandMode="DataGridExpandMode.Single"
                    Data="@_orders" TItem="Order" EditMode="DataGridEditMode.Single" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" @bind-Value="@SelectedOrders"
                    ShowExpandColumn="false" ShowPagingSummary="true" AllowColumnResize="true" RowRender="@RowRender">
...
    <Columns>
            <RadzenDataGridColumn TItem="Order" Property="Id" Title="Order ID" Width="120px"/>
            <RadzenDataGridColumn TItem="Order" Property="Customer.Name" Title="Customer" Width="200px">
                <EditTemplate Context="order">
                    <RadzenDropDownDataGrid TValue="int"  AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains"
                                            Data=@_customers Count="5" TextProperty="Name" ValueProperty="Id"
                                            Class="w-100" @bind-Value="order.CustomerId"/>
                                        
                </EditTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="Order" Property="OrderDateTime" Title="Order Date" Width="200px">
                <Template Context="order">
                    @($"{order.OrderDateTime:dd/MM/yyyy}")
                </Template>
                <EditTemplate Context="order">
                    <RadzenDatePicker @bind-Value="order.OrderDateTime" DateFormat="dd/MM/yyyy HH:mm" Class="w-100"/>
                </EditTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="Order" Property="Status" Title="Status" Width="100px">
    ...

【问题讨论】:

    标签: blazor-server-side radzen


    【解决方案1】:

    使用模板属性评估对象属性值:

    <RadzenDataGrid Data="@_orders" TItem="Order" RowUpdate="@OnUpdateRow" ...>
                        
        <Columns>
                <RadzenDataGridColumn Width="50px" TItem="Order">
            <Template Context="o">
                @if (order.Data.Status=="Completed")
                {
                    <RadzenButton Disabled ButtonStyle="ButtonStyle.Success" Icon="done" />
                } else
                {
     
                    <RadzenButton ButtonStyle="ButtonStyle.Danger"  />
                }
            </Template>
        </RadzenDataGridColumn>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 2011-05-11
      • 2011-04-03
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多