How to conditionally display grid cell data based upon the row context?

1 Answer 48 Views
Grid
David
Top achievements
Rank 2
Iron
David asked on 21 Jun 2022, 07:34 AM

Situation: I have an EF table being displayed in a Telerik Grid.

There is a command field which when clicked goes to a page to an action page that consumes the the record for that row.

I want the button to display in rows that meet a condition in that row's data.

Status (an enum) is the field that will if a certain value the condition is true.

So I guess I need access to row's context. ???


                <GridColumn Field="@(nameof(RecordResult.Status))" Title="Status" Width="80px" />
                <GridCommandColumn Title="Update" Width="80px">
                    <GridCommandButton Command="MyOwnCommand" Icon="Information" OnClick="@MyCustomCommandHandler">
                    Claim
                    </GridCommandButton>
                </GridCommandColumn>
            </GridColumns>
        </TelerikGrid>

David
Top achievements
Rank 2
Iron
commented on 22 Jun 2022, 12:42 PM

I have tried using context as per Blazor Grid - Overview


        <GridColumn Field="@nameof(ProductDto.Discontinued)" Width="135px" Title="Discontinued" Editable="false" TextAlign="@ColumnTextAlign.Center">
            <Template>
                @{
                    var product = context as ProductDto;

                    if (product.Discontinued.GetValueOrDefault())
                    {
                        <span class="k-badge k-badge-md k-badge-solid k-badge-rounded k-badge-error">Discontinued</span>
                    }
                    else
                    {
                        <span class="k-badge k-badge-md k-badge-solid k-badge-rounded k-badge-success">Available</span>
                    }
                }
            </Template>
        </GridColumn

 

My code:


                <GridColumn Field="@(nameof(RecordResult.Status))" Title="Claims">
                    <template>
                        @{
                            var product = context as RecordResult;
                            if (product.Status == recordStatus.current)
                            {
                                <GridCommandButton Command="MyOwnCommand" Icon="Information" OnClick="@MyCustomCommandHandler">
                                    Claim
                                </GridCommandButton>
                            }
                            else
                            {
                                <span class="k-badge k-badge-md k-badge-solid k-badge-rounded k-badge-success">&nbsp;</span>
                            }
                        }
                    </template>
                </GridColumn>

But compiler doesn't like the context entity.

The name 'context' does not exist in the current context

David
Top achievements
Rank 2
Iron
commented on 23 Jun 2022, 01:43 PM

Did an upgrade to V3.4.0  . The following now works.

                <GridColumn Field="@(nameof(RecordResult.Status))" Title="Status" Width="80px" />
                <GridColumn Field="@(nameof(RecordResult.Status))" Title="Claim" Width="80px">
                    <Template>
                        @{
                            var recordResult = context as RecordResult;
                            if (recordResult.Status == recordStatus.current)
                            {
                                                <TelerikButton Icon="Information" 
                                                               @onclick="() => MyCustomCommandHandler(recordResult)"
                                                               >Claim</TelerikButton>
                            }
                            else
                            {
                                
                            }
                        }
                    </Template>
                </GridColumn>
Ps: Could put conditional in Template in a CommandField.

1 Answer, 1 is accepted

Sort by
0
Accepted
David
Top achievements
Rank 2
Iron
answered on 23 Jun 2022, 01:44 PM
As per my last comment.
Tags
Grid
Asked by
David
Top achievements
Rank 2
Iron
Answers by
David
Top achievements
Rank 2
Iron
Share this question
or