Skip to content

Added new kb article grid-popup-in-cell #3016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kendo-bot
Copy link
Collaborator

No description provided.

@kendo-bot kendo-bot requested a review from a team as a code owner June 12, 2025 12:19
@xristianstefanov xristianstefanov self-assigned this Jun 12, 2025
@xristianstefanov xristianstefanov added the merge-to-production Use this label to get a comment to choose whether to merge the PR to production label Jun 12, 2025

I want to display a Popup beside an icon embedded within a cell in the [Grid for Blazor](slug:grid-overview). The Popup should appear when the icon is clicked.

## Solution
Copy link
Contributor

@dimodi dimodi Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a solution without duplicate popup instances in each cell. For example the Popover can achieve this. If you use a GridCommandColumn, you will get the data item in the Button's click handler automatically.

<TelerikGrid Data="@GridData"
             TItem="@SampleModel"
             Pageable="true"
             Sortable="true"
             FilterMode="GridFilterMode.FilterRow">
    <GridColumns>
        <GridCommandColumn>
            @{
                var dataItem = (SampleModel)context;
            }
            <GridCommandButton Id="@( $"button{dataItem.Id}" )" Icon="@SvgIcon.DocumentManager"
                               OnClick="@OnPopupShowButtonClick" />
        </GridCommandColumn>
        <GridColumn Field="@nameof(SampleModel.Price)" />
        <GridColumn Field="@nameof(SampleModel.Quantity)" />
    </GridColumns>
</TelerikGrid>

<TelerikPopover @ref="@PopoverRef"
                AnchorSelector="@PopoverAnchorSelector"
                Position="@PopoverPosition.Right"
                Offset="20"
                Width="240px"
                Height="140px">
    <PopoverHeader>
        Popover for @ModelInPopup?.Name
    </PopoverHeader>
    <PopoverContent>
        <div style="padding:2em;">
            <TelerikButton OnClick="@( () => PopoverRef?.Hide() )">Hide</TelerikButton>
        </div>
    </PopoverContent>
</TelerikPopover>

@code {
    private List<SampleModel> GridData { get; set; } = new();
    private TelerikPopover? PopoverRef { get; set; }

    private string PopoverAnchorSelector { get; set; } = "#button1";

    private SampleModel? ModelInPopup { get; set; }

    private async Task OnPopupShowButtonClick(GridCommandEventArgs args)
    {
        ModelInPopup = (SampleModel)args.Item;

        PopoverRef?.Hide();
        PopoverAnchorSelector = $"#button{ModelInPopup.Id}";
        await Task.Delay(1);

        PopoverRef?.Show();
    }

    protected override void OnInitialized()
    {
        var rnd = new Random();
        for (int i = 1; i <= 7; i++)
        {
            GridData.Add(new SampleModel()
            {
                Id = i,
                Name = $"Name {i}",
                GroupName = $"Group {i % 3 + 1}",
                Price = rnd.Next(1, 100) * 1.23m,
                Quantity = rnd.Next(0, 1000),
                StartDate = DateTime.Now.AddDays(-rnd.Next(60, 1000)),
                IsActive = i % 4 > 0
            });
        }
    }
    public class SampleModel
    {
        public int Id { get; set; }
        public int? ParentId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string GroupName { get; set; } = string.Empty;
        public decimal Price { get; set; }
        public int Quantity { get; set; }
        public object Icon { get; set; } = SvgIcon.File;
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public bool IsActive { get; set; }
    }
}

}
<TelerikButton Id="@( $"button{dataItem.Id}" )" Icon="@SvgIcon.DocumentManager"
OnClick="@( () => PopupRefs[dataItem.Id]?.Show() )" />
<TelerikPopup @ref="@PopupRefs[dataItem.Id]"
Copy link
Contributor

@dimodi dimodi Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave this example too, but warn about potential performance issues with a large number of rendered rows.

type: how-to
page_title: How to Display Popup Next to Icon in Grid for Blazor
slug: grid-kb-popup-in-cell
tags: grid, blazor, popup, cell
Copy link
Contributor

@dimodi dimodi Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tags: grid, blazor, popup, cell
tags: blazor, grid, popup, template

Comment on lines +31 to +33
1. Define a dictionary to store references to all popups associated with the Grid items. This ensures that each Popup has a unique identifier tied to its corresponding item.

2. Use the `AnchorSelector` parameter of the `TelerikPopup` component to dynamically associate each popup with its corresponding icon. Set the `AnchorSelector` to the unique ID of the icon element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a little more detailed steps with links to each applicable feature or component.

  • Grid column template
  • Popup / Popover Overview

@dimodi
Copy link
Contributor

dimodi commented Jun 12, 2025

merge-to-production no longer makes a difference, because third-party actions are disabled. Create a new PR for the production branch once this one is merged, or ping me to cherry-pick manually.

@xristianstefanov xristianstefanov removed the merge-to-production Use this label to get a comment to choose whether to merge the PR to production label Jun 12, 2025
@dimodi dimodi added the merge-to-production Use this label to get a comment to choose whether to merge the PR to production label Jun 16, 2025
Copy link
Contributor

Hello @dimodi,

Check the below option if you would like to automatically generate PR to production. The automation uses the branch for the cherry-pick, and then will delete the branch. Please, do not delete it manually.

  • create PR to production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-to-production Use this label to get a comment to choose whether to merge the PR to production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants