|
<SfContextMenu Target=".e-tab-header" TValue="MenuItem">
<MenuItems>
<MenuItem Text="Close" Id="Close"></MenuItem>
<MenuItem Text="Close All" Id="All"></MenuItem>
<MenuItem Text="Close All But this" Id="NotThis"></MenuItem>
</MenuItems>
<MenuEvents TValue="MenuItem" OnOpen="OnOpen" ItemSelected="OnItemSelected"></MenuEvents>
</SfContextMenu>
public async Task OnOpen(BeforeOpenCloseMenuEventArgs<MenuItem> args)
{
string selectedIndex = await jsRuntime.InvokeAsync<string>("OnHeader", args.Left, args.Top); //to get the choosen tab index
ContextMenuIndex = Convert.ToInt32(selectedIndex);
}
public async Task OnItemSelected(MenuEventArgs<MenuItem> args)
{
var SelectedMenuItem = args.Item.Id;
switch (SelectedMenuItem)
{
case "Close":
await TabRef.RemoveTab(ContextMenuIndex); //close the choosen tab alone
break;
case "All":
int c = TabRef.Items.Count;
for (int i = c - 1; i >= 0; i--) // close all the tabs available
{
await TabRef.RemoveTab(i);
}
break;
case "NotThis":
int co = TabRef.Items.Count;
for (int i = co-1; i >= 0; i--)
{
if (i != ContextMenuIndex) //to prevent closing of the choosen tab
{
await TabRef.RemoveTab(i);
}
}
break;
}
} |
|
function OnHeader(left, top) {
return document.elementFromPoint(left, top).closest('.e-toolbar-item').getAttribute('data-index');
} |
|
<script src="~/Script.js"></script> |
|
<DashboardLayoutPanel Id="Panel1" SizeX="4" SizeY="2">
<ContentTemplate>
<div style="width:100%; padding:5px;">
<SfContextMenu Target=".e-tab-header" TValue="MenuItem">
<MenuItems>
<MenuItem Text="Close" Id="Close"></MenuItem>
<MenuItem Text="Close All" Id="All"></MenuItem>
<MenuItem Text="Close All But this" Id="NotThis"></MenuItem>
</MenuItems>
<MenuEvents TValue="MenuItem" OnOpen="OnOpen" ItemSelected="OnItemSelected"></MenuEvents>
</SfContextMenu>
<SfTab CssClass="e-dashboard-tab" ShowCloseButton="true" @ref="TabRef">
<TabItems>
<TabItem Content="This SfTab is within DashboardLayoutPanel">
<ChildContent>
<TabHeader Text="Twitter"></TabHeader>
</ChildContent>
</TabItem>
<TabItem Content="Facebook is an online social networking service headquartered in Menlo Park, California. Its website waslaunched on February 4, 2004, by Mark Zuckerberg with his Harvard College roommates and fellow students EduardoSaverin, Andrew McCollum, Dustin Moskovitz and Chris Hughes.">
<ChildContent>
<TabHeader Text="Facebook"></TabHeader>
</ChildContent>
</TabItem>
<TabItem>
<HeaderTemplate>Grid</HeaderTemplate>
<ContentTemplate>
<SfGrid DataSource="@Orders">
<GridPageSettings></GridPageSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="yMd" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
</ContentTemplate>
</TabItem>
</TabItems>
</SfTab>
</div>
</ContentTemplate>
</DashboardLayoutPanel> |
Hello~
In the latest version(20.1.0.47),this sample didn't work. Is this a new bug ? Could you please have a try.
Thank you
Hi OuYuanbin,
No. This is not a defect and we would like to let you know that we have made two breaking changes in the 20.1 version. Please follow below release notes and make the necessary changes to your project.
https://blazor.syncfusion.com/documentation/release-notes/20.1.47?type=all#breaking-changes