-
Notifications
You must be signed in to change notification settings - Fork 78
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
base: master
Are you sure you want to change the base?
Added new kb article grid-popup-in-cell #3016
Conversation
|
||
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 |
There was a problem hiding this comment.
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]" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags: grid, blazor, popup, cell | |
tags: blazor, grid, popup, template |
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. |
There was a problem hiding this comment.
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
|
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.
|
No description provided.