Skip to content

Commit ff576c7

Browse files
chore(Grid): add suggestions
1 parent c0965c6 commit ff576c7

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

knowledge-base/grid-popup-in-cell.md

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to display a popup beside an icon embedded in a cell of t
44
type: how-to
55
page_title: How to Display Popup Next to Icon in Grid for Blazor
66
slug: grid-kb-popup-in-cell
7-
tags: grid, blazor, popup, cell
7+
tags: blazor, grid, popup, template
88
res_type: kb
99
ticketid: 1689992, 1640846
1010
---
@@ -22,15 +22,15 @@ ticketid: 1689992, 1640846
2222

2323
## Description
2424

25-
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.
25+
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.
2626

2727
## Solution
2828

29-
To display a Popup within a grid cell:
29+
To display a popup within a Grid cell:
3030

31-
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.
31+
1. Add a button that triggers the popup for each row by using a `GridCommandColumn` or a column [`Template`](slug:grid-templates-column).
3232

33-
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.
33+
2. Anchor the [`Popover`](slug:popover-overview) to the button via `AnchorSelector`.
3434

3535
Here is an example implementation:
3636

@@ -41,45 +41,56 @@ Here is an example implementation:
4141
Sortable="true"
4242
FilterMode="GridFilterMode.FilterRow">
4343
<GridColumns>
44-
<GridColumn Field="@nameof(SampleModel.Name)">
45-
<Template>
46-
@{
47-
var dataItem = (SampleModel)context;
48-
if (!PopupRefs.ContainsKey(dataItem.Id))
49-
{
50-
PopupRefs.Add(dataItem.Id, null);
51-
}
52-
}
53-
<TelerikButton Id="@( $"button{dataItem.Id}" )" Icon="@SvgIcon.DocumentManager"
54-
OnClick="@( () => PopupRefs[dataItem.Id]?.Show() )" />
55-
<TelerikPopup @ref="@PopupRefs[dataItem.Id]"
56-
AnchorSelector="@( $"#button{dataItem.Id}" )"
57-
AnchorHorizontalAlign="@PopupAnchorHorizontalAlign.Right"
58-
AnchorVerticalAlign="@PopupAnchorVerticalAlign.Top"
59-
HorizontalAlign="@PopupHorizontalAlign.Left"
60-
VerticalAlign="@PopupVerticalAlign.Top"
61-
Width="240px"
62-
Height="140px">
63-
<div style="padding:2em;">
64-
Popup for item
65-
<TelerikButton OnClick="@( () => PopupRefs[dataItem.Id]?.Hide() )">Hide Popup for @dataItem.Name</TelerikButton>
66-
</div>
67-
</TelerikPopup>
68-
</Template>
69-
</GridColumn>
44+
<GridCommandColumn>
45+
@{
46+
var dataItem = (SampleModel)context;
47+
}
48+
<GridCommandButton Id="@( $"button{dataItem.Id}" )" Icon="@SvgIcon.DocumentManager"
49+
OnClick="@OnPopupShowButtonClick" />
50+
</GridCommandColumn>
7051
<GridColumn Field="@nameof(SampleModel.Price)" />
7152
<GridColumn Field="@nameof(SampleModel.Quantity)" />
7253
</GridColumns>
7354
</TelerikGrid>
7455
56+
<TelerikPopover @ref="@PopoverRef"
57+
AnchorSelector="@PopoverAnchorSelector"
58+
Position="@PopoverPosition.Right"
59+
Offset="20"
60+
Width="240px"
61+
Height="140px">
62+
<PopoverHeader>
63+
Popover for @ModelInPopup?.Name
64+
</PopoverHeader>
65+
<PopoverContent>
66+
<div style="padding:2em;">
67+
<TelerikButton OnClick="@( () => PopoverRef?.Hide() )">Hide</TelerikButton>
68+
</div>
69+
</PopoverContent>
70+
</TelerikPopover>
71+
7572
@code {
7673
private List<SampleModel> GridData { get; set; } = new();
77-
private Dictionary<int, TelerikPopup?> PopupRefs { get; set; } = new();
74+
private TelerikPopover? PopoverRef { get; set; }
75+
76+
private string PopoverAnchorSelector { get; set; } = "#button1";
77+
78+
private SampleModel? ModelInPopup { get; set; }
79+
80+
private async Task OnPopupShowButtonClick(GridCommandEventArgs args)
81+
{
82+
ModelInPopup = (SampleModel)args.Item;
83+
84+
PopoverRef?.Hide();
85+
PopoverAnchorSelector = $"#button{ModelInPopup.Id}";
86+
await Task.Delay(1);
87+
88+
PopoverRef?.Show();
89+
}
7890
7991
protected override void OnInitialized()
8092
{
8193
var rnd = new Random();
82-
8394
for (int i = 1; i <= 7; i++)
8495
{
8596
GridData.Add(new SampleModel()
@@ -94,7 +105,6 @@ Here is an example implementation:
94105
});
95106
}
96107
}
97-
98108
public class SampleModel
99109
{
100110
public int Id { get; set; }
@@ -114,4 +124,4 @@ Here is an example implementation:
114124
## See Also
115125

116126
* [Grid Overview Documentation](slug:grid-overview)
117-
* [Popup Overview Documentation](slug:popup-overview)
127+
* [Popover Overview Documentation](slug:popover-overview)

0 commit comments

Comments
 (0)