|
<SfButton @onclick="@OpenDialog">Open Dialog</SfButton>
<SfDialog Width="800px" ShowCloseIcon="true" IsModal="true" @bind-Visible="@IsVisible">
<DialogTemplates>
<Header> Dialog </Header>
<Content>
<button @onclick="Data2">Set 2 Records</button>
<button @onclick="Data3">Set 3 Records</button>
<button @onclick="Data4">Set 4 Records</button>
<button @onclick="Data1">Set 10 Records</button>
<SfGrid @ref="DefaultGrid" DataSource="@Orders" Height="@GridHeight" RowHeight="@GridRowHeight">
<GridEvents DataBound="DataBoundHandler" TValue="Order"></GridEvents>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
</Content>
</DialogTemplates>
<DialogButtons>
<DialogButton Content="OK" IsPrimary="true" OnClick="@CloseDialog" />
<DialogButton Content="Cancel" OnClick="@CloseDialog" />
</DialogButtons>
</SfDialog>
@code{
private SfGrid<Order> DefaultGrid;
public string GridHeight = "auto"; //set default height as auto
public double MaxGridHeight { get; set; } = 250; //define max height- (when the number of records * grid row height - is exceed then scrollbar will appear)
public List<Order> Orders { get; set; }
double GridRowHeight { get; set; } = 40;
. . .
public async Task DataBoundHandler()
{
int count = (await DefaultGrid.GetCurrentViewRecords()).Count(); //get current view records count
double CalcultedHeight = count * GridRowHeight; //calculate the height with number of records and Grid Row height
GridHeight = CalcultedHeight < MaxGridHeight ? "auto" : MaxGridHeight.ToString(); //set the Grid height based on the calculated height and Grid max height
}
} |
|
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons
@inject IJSRuntime Runtime
<SfButton @onclick="@OpenDialog">Open Dialog</SfButton>
<SfDialog Width="800px" ShowCloseIcon="true" IsModal="true" @bind-Visible="@IsVisible">
<DialogTemplates>
<Header> Dialog </Header>
<Content>
<button @onclick="Data2">Set 2 Records</button>
<button @onclick="Data3">Set 3 Records</button>
<button @onclick="Data4">Set 4 Records</button>
<button @onclick="Data1">Set 10 Records</button>
<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="@Orders" Height="300">
<GridEvents DataBound="DataBoundHandler" TValue="Order"></GridEvents>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
</Content>
</DialogTemplates>
<DialogButtons>
<DialogButton Content="OK" IsPrimary="true" OnClick="@CloseDialog" />
<DialogButton Content="Cancel" OnClick="@CloseDialog" />
</DialogButtons>
</SfDialog>
@code{
private SfGrid<Order> DefaultGrid;
public List<Order> Orders { get; set; }
. ..
public async Task DataBoundHandler()
{
await Runtime.InvokeVoidAsync("hideScroll", DefaultGrid.ID); // called interop function for show /hide the scrollbar
}
} |
|
[Interop.js]
function hideScroll(id) {
var gridContent = document.getElementsByClassName("e-content")[0];
var scrollHeight = document.getElementById(id + "_content_table").scrollHeight;
if (scrollHeight < gridContent.clientHeight) {
gridContent.style.overflowY = "auto";
document.getElementsByClassName("e-gridheader")[0].style.paddingRight = "";
} else {
document.getElementsByClassName("e-gridheader")[0].style.paddingRight = "16px";
}
} |
|
[_Host.cshtml]
<head>
. . .>
<link rel='nofollow' href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" />
<script src="~/Interop.js"></script>
</head> |