MatBlazor icon indicating copy to clipboard operation
MatBlazor copied to clipboard

Highlight Row of a MatTable

Open markiemarkus opened this issue 6 years ago • 3 comments

Is there a way to highlight a MatTableRow based on conditional values in the row? i.e. where @context.Prediction = @context.Result <MatTableRow>

@context.RowID @context.Name ... ... @context.Result @context.Prediction
</MatTableRow>

markiemarkus avatar Feb 25 '20 17:02 markiemarkus

No, it's not possible. Internally in MatTable the TableRows (which is the class that holds the Selected property) are created by enumerating the items of the MatTable and rendering them according to the razor you put inside the MatTableRow parameter. The Selected property is only modified by the toggle from the onClick handler

@foreach (var item in ItemList)
{
    <TableRow Class="@RowClass" AllowSelection="@AllowSelection">@MatTableRow(item)</TableRow>
}

lindespang avatar Mar 04 '20 20:03 lindespang

@markiemarkus , Can this be closed?

Christian-Oleson avatar Dec 13 '20 21:12 Christian-Oleson

Below work-around worked for me.

Add a custom component and capture the Cascading Parameter Table Row and set Selected property via a parameter binding.

Eg Container component:


@ChildContent

@code{
    [Parameter]
    public RenderFragment ChildContent { get; set; }

    [Parameter]
    public bool IsSelected
    {
        get => Row == null ? false : Row.Selected;
        set
        {
            if (Row == null) return;
            Row.Selected = value;
        }
    }

    [CascadingParameter]
    public TableRow Row { get; set; }
}

jcb871 avatar Jul 13 '21 12:07 jcb871