The following KB article shows a workaround for removing the Grid aggregate labels ("Sum" and "Count") from the exported Excel document: https://www.telerik.com/blazor-ui/documentation/knowledge-base/grid-remove-aggregate-labels-in-excel-footr
It would be nice to have this option as a parameter in the Grid. It would allow to toggle on/off this behavior, instead of having to rely on custom code to work around it.
Or in the OnBeforeExport method, add extra data to GridBeforeExcelExportEventArgs that contains the aggregates so they can be changed.
private async Task OnBeforeExcelExport(GridBeforeExcelExportEventArgs args)
{
await Task.CompletedTask;
// Loop through all columns and fix the footer aggregate values
// Replace the default "Sum: 1234.56" text with just the decimal number
foreach (var column in args.Columns)
{
if (column.HasAggregate)
{
// Set the number format for the column so Excel treats it as a number
column.Aggregate.Field.Value == "MyNewValue";
}
}
}I created a subclass of the TelerikGrid to extend the limited built-in search functionality.
To do that, I use the GridStateChanged event to rewrite the SearchFilter: I replace the default filter with a more complex CompositeFilterDescriptor (including highlighting). This works perfectly during normal interaction.
Now I also want the search to be persisted, so that after reloading the page the grid shows the same search again. Saving the grid state is not a problem, but when restoring the saved state during OnStateInit / GridStateInit, the following exception occurs:
Unable to cast object of type 'Telerik.DataSource.CompositeFilterDescriptor' to type 'Telerik.DataSource.FilterDescriptor'.
System.InvalidCastException: Unable to cast object of type 'Telerik.DataSource.CompositeFilterDescriptor' to type 'Telerik.DataSource.FilterDescriptor'.
at Telerik.Blazor.Components.Common.TableGridBase`2.LoadSearchFilter(IFilterDescriptor descriptor)
at Telerik.Blazor.Components.TelerikGrid`1.SetStateInternalAsync(GridState`1 state)
at Telerik.Blazor.Components.TelerikGrid`1.InvokeOnStateInit()
at Telerik.Blazor.Components.TelerikGrid`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'MYsaCsOgfpbyHeO0xNFpA7ViPHNUC6rpc1K9eIwVR5Y'.
System.InvalidCastException: Unable to cast object of type 'Telerik.DataSource.CompositeFilterDescriptor' to type 'Telerik.DataSource.FilterDescriptor'.
at Telerik.Blazor.Components.Common.TableGridBase`2.LoadSearchFilter(IFilterDescriptor descriptor)
at Telerik.Blazor.Components.TelerikGrid`1.SetStateInternalAsync(GridState`1 state)
at Telerik.Blazor.Components.TelerikGrid`1.InvokeOnStateInit()
at Telerik.Blazor.Components.TelerikGrid`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)I also tried saving the search term and the selected columns separately and then restoring the state in OnAfterRender, but at that point the SearchFilter can no longer be set.
Sincerly Daniel
Hello,
we recently updated Telerik.UI.for.Blazor from 9.0.0 to 12.3.0, afterwords we noticed that in several instances where we use the `TelerikGrid` component, keyboard interactions stopped working. Specifically the `@onkeydown` seems to no longer propagate to parent elements of the grid. As this was not mentioned in the Breaking changes for the version 10 or 12 releases we assume this to be a bug.
here a simplified example:
<div style="padding: 0; width: @(ShowSidePanel ? "65%" : "99%")" tabindex="0" @onkeydown="@(OnKeyPress)">
<TelerikGrid TItem="IncomingInvoiceGridItemViewModel"
@ref="GridRef"
Class="admin-grid"
Height="@OverviewHeight"
RowHeight="50"
Pageable="false"
PageSize="PageSize"
FilterMode="@GridFilterMode.FilterMenu"
Sortable="true"
Resizable="true"
Reorderable="true"
ShowColumnMenu="true"
ScrollMode="@GridScrollMode.Virtual"
SelectionMode="@GridSelectionMode.Single"
OnStateInit="@OnStateInit_SetStateAsync"
OnStateChanged="@OnStateChanged_SaveStateAsync"
SelectedItemsChanged="@OnSelectedItemsChanged_LoadPdf"
OnRead="@OnRead_UpdateFilteredItems">
<GridSettings>
<GridColumnMenuSettings Lockable="false" />
</GridSettings>
...
<!-- aggregates, columns and noDataTemplate omitted -->
...
</TelerikGrid>
</div>Implementation / usages of the features did not change, only updates where changes required by the update Telerik.UI.for.Blazor from 9.0.0 to 12.3.0.
These were the dependencies updated alongside the update of Telerik.UI.for.Blazor from 9.0.0 to 12.3.0 :
Hello,
seems like the GridToolbar(even the GridToolbarTemplate) in grid is not rendering "GridToolBarOverflowMode.Section". The "Scroll" mode is ok.
Is there any additional setup, or did i missed some setup...?
REPL:
https://blazorrepl.telerik.com/wqYQvvEq40GkajEZ30
based on:
https://www.telerik.com/blazor-ui/documentation/components/grid/toolbar
some mention about "sections" but it seems for another purpose:
https://www.telerik.com/blazor-ui/documentation/knowledge-base/common-net8-sections
Thanks
The Grid's CheckBoxColumn doesn't support the TextAlign property, making it impossible to center the checkbox with just Grid markup, you have to resort to a workaround.
The TextAlign property in other columns causes style="text-align: center" to be added to the underlying table cell. This would also work for the checkbox column.
See this test:
<table class="table">
<tr>
<td class="table-active" style="width: 40px; text-align: center"><input type="checkbox" /> </td>
<td>test</td>
</tr>
</table>Please add the TextAlign property to the CheckboxColumn.
I want to reorder the Grid rows the same way I can reorder the columns - via the keyboard.
For reference: Telerik jQuery Grid drag and drop
Column headers and column data do not match after reordering.
See this example: https://blazorrepl.telerik.com/GKkFcwlF54CvZoVp34
1. Reorder Group 1 and Group 2.
2. The column headers within these 2 groups are not reordered with their parent.
Reordering should work according to the rules specified in the documentation: https://www.telerik.com/blazor-ui/documentation/components/grid/columns/multi-column-headers#reordering
Hello,
there is inconsistency/behaviour/order in events of the Grid: OnStateInit and OnRead. Which leads to scenario with no clear sollution and would be nice to fix it, and how to solve it as "hotfix".
Also i think its not new in 12.x. release, it exists longer ;)
<TelerikGrid TItem="GData" @ref="gHL" OnRead=@GReadItems OnStateInit="@OnStateGHL">
...
<GridAggregates>
@if(1==2){...}
</GridAggregates>
@code{
protected async Task GReadItems(GridReadEventArgs args)
{
**hack for C)
if(gHL==null)return;//state init AVOID 2x call gread PRIOR OnStateInit
...// must be called:
args.AggregateResults = rr.ToDataSourceResult(args.Request).AggregateResults;
...
}
void OnStateGHL(GridStateEventArgs<GData> args) //or async Task doesnt matter
{
//default SORTing:args.GridState = new GridState<GData>
{
SortDescriptors = new List<Telerik.DataSource.SortDescriptor>
{
new Telerik.DataSource.SortDescriptor{ Member = nameof(GData.DatPorizeni), SortDirection = Telerik.DataSource.ListSortDirection.Descending },
//new Telerik.DataSource.SortDescriptor{ Member = nameof(GData.Skupina), SortDirection = Telerik.DataSource.ListSortDirection.Ascending }
}
};
}
}
Problematic scenarios, single page, same grid:
A) when NO aggregates markup EXISTS at all
1. OnStateInit
2. OnRead - gHL IS NULL
=OK
B) when EMPTY aggregates markup EXISTS
1. OnRead
2. OnStateInit
=FAIL
HOW to read and ui data with correct STATE?
https://www.telerik.com/blazor-ui/documentation/components/grid/state
cannot call gHL.rebind, also gHL is null
NONE initinal "sorting,filtering etc" is set, WRONG data,columns,displayed to the user
C) when SOME real aggregates markup EXISTS
1. OnRead
2. OnStateInit
3. OnRead
=partial FAIL("**hack used"), but managed by if(gHL==null)return
D) "hotfix" used with GridAggregates="@( HasAggregates ? GridAggregatesTemplate : null )"
act as A or C, but gHL is always null, which is also bad againts C)
Expected:
ALWAYS only A) - First 1.OnStateInit THEN 2.OnRead. its the best one, without any additional hacks = UNIFY the event orders and behaviour.
OR
A) or C)
everything else is unmanagable.
Especially when initial sorting "is must" and aggregates,columns and so on, are managed by user(non static)
B) is completly WRONG: incorrect event order of OnStateInit and OnRead
D) is againts C) (cannot detect reference of gHL)
related to:
https://feedback.telerik.com/blazor/1654029-onstateinit-does-not-fire-if-gridaggregates-exists-but-is-empty
https://www.telerik.com/forums/grid-onstateinit-event-and-onread-event-chaos
OR how to solve it generally = what is the way to LOAD gridState, and after that, LOAD Data by defined GridState?
Thanks
On the bright side, I don't have to write a repro code sample for this issue since this is present in the example on https://www.telerik.com/blazor-ui/documentation/components/grid/templates/popup-form-template#example
The popup for adding a new item now shows the values of the previously edited item. The same goes for editing any other item. As long as the popup is closed with the "x" in the top right, the edit context remains.
The Problem relates to the ExitGridEditMode method and when it is and isn't called. Specifically, it is not called when the edit popup is closed with the close button in the top right of the window. I have also not found any way to get notified about the edit popup being closed with the close button. The Grid contains a hard-coded <TelerikWindow> and there doesn't appear to be a way to influence this window action or any events that it triggers.
1. User clicks the sparkled button that opens the AI window in this demo: https://demos.telerik.com/blazor-ui/grid/ai-data-operations
2. User chooses a predefined prompt suggestion, enters one via the keyboard, or uses voice access to dictate one, and clicks apply. The operation runs successfully and returns output.
3. Now the user clicks the sparkled button again, and the AI window opens. Once open, the prompt text box fills with the previously entered request text.
How to remove or prevent the previously entered request text from filling the text box on every sequential opening of the AI window?
When triggering Grid edit mode through the Grid state and the component is using adaptive mode, the edit form doesn't show.
Possible workarounds include:
The Grid in-cell editor will not close if the user selects content in more than one cell in the component. This can lead to problems related to uncommitted new values if the user "forgets" to confirm their edits and navigates away.
https://demos.telerik.com/blazor-ui/grid/editing-incell
Observe the inconsistency:
===
A possible workaround is to use @onfocusout and the Grid state to detect the problematic behavior and close the edit cell programmatically:
When going fast over the Grid rows with the mouse cursor, the rows are highlighted after a delay. The delay is more noticeable on higher resolutions (2560x1440 or higher).
In the app that targets .NET10 the row hover styles are applied with a delay, whereas in the app that targets .NET8 the hover styles are applied as soon as the mouse enters the boundaries of a row.
Similar performance in applying hover-related styles.
All
No response
Please add support for programmatic exporting of Grids (SaveAsExcelFileAsync() and ExportToExcelAsync() ) with a GridExcelExportOptions argument and multi-column headers.
===
A potential workaround is to programmatically click the built-in export command button, which can even be hidden:
@using Telerik.Blazor.Components.Grid
@inject IJSRuntime JS
<PageTitle>Home</PageTitle>
<TelerikGrid Data="@GridData">
<GridToolBarTemplate>
<TelerikButton OnClick="@ExportGridWithOtherColumns">Export Programmatically</TelerikButton>
<GridCommandButton Class="hidden-export-button" Command="ExcelExport">Export Natively</GridCommandButton>
</GridToolBarTemplate>
<GridSettings>
<GridExcelExport OnBeforeExport="@OnGridBeforeExport" />
</GridSettings>
<GridColumns>
<GridColumn Field="@nameof(Product.Id)" Width="100px" />
<GridColumn Field="@nameof(Product.Name)" Width="120px" />
<GridColumn Title="Product Details">
<Columns>
<GridColumn Field="@nameof(Product.Group)" Width="180px" />
<GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:c2}" Width="120px" />
<GridColumn Field="@nameof(Product.Quantity)" DisplayFormat="{0:n0}" Width="120px" />
<GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:d}" Width="180px" />
<GridColumn Field="@nameof(Product.Discontinued)" Width="100px" />
</Columns>
</GridColumn>
</GridColumns>
</TelerikGrid>
<style>
.hidden-export-button {
display: none;
}
</style>
<script suppress-error="BL9992">
function clickExportCommandButton() {
let hiddenExportButton = document.querySelector(".hidden-export-button");
if (hiddenExportButton) {
hiddenExportButton.click();
}
}
</script>
@code {
private List<Product> GridData { get; set; } = new();
private void OnGridBeforeExport(GridBeforeExcelExportEventArgs args)
{
List<string> exportableColumnFields = new List<string> { nameof(Product.Name), nameof(Product.Price), nameof(Product.Quantity) };
List<GridExcelExportColumn> ColumnsToExport = new();
foreach (GridExcelExportColumn column in args.Columns)
{
if (exportableColumnFields.Contains(column.Field))
{
ColumnsToExport.Add(column);
}
}
args.Columns = ColumnsToExport;
}
private async Task ExportGridWithOtherColumns()
{
await JS.InvokeVoidAsync("clickExportCommandButton");
}
protected override void OnInitialized()
{
var rnd = Random.Shared;
for (int i = 1; i <= 7; i++)
{
GridData.Add(new Product()
{
Id = i,
Name = $"Name {i} {(char)rnd.Next(65, 91)}{(char)rnd.Next(65, 91)}",
Group = $"Group {i % 3 + 1}",
Price = rnd.Next(1, 100) * 1.23m,
Quantity = rnd.Next(0, 10000),
Released = DateTime.Today.AddDays(-rnd.Next(60, 1000)),
Discontinued = i % 4 == 0
});
}
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Group { get; set; } = string.Empty;
public decimal Price { get; set; }
public int Quantity { get; set; }
public DateTime Released { get; set; }
public bool Discontinued { get; set; }
}
}
Workaround:
<TelerikGrid Data="@GridData"
SelectionMode="@GridSelectionMode.Multiple"
SelectedItems="@SelectedItems"
SelectedItemsChanged="@( (IEnumerable<Employee> newSelected) => OnSelectedItemsChanged(newSelected) )"
Height="300px">
<GridToolBarTemplate>
<TelerikButton Enabled="@(SelectedItems.Any())" OnClick="@DeleteSelectedEmployees">Delete</TelerikButton>
</GridToolBarTemplate>
<GridColumns>
<GridCheckboxColumn SelectAll="true" />
<GridColumn Field="Name" Title="Name" />
<GridColumn Field="Team" Title="Team" />
</GridColumns>
</TelerikGrid>
@code {
private List<Employee> GridData { get; set; } = Enumerable.Range(1, 10).Select(i => new Employee
{
EmployeeId = i,
Name = $"Employee {i}",
Team = $"Team {i % 3}"
}).ToList();
private List<Employee> SelectedItems { get; set; } = new();
private void OnSelectedItemsChanged(IEnumerable<Employee> items)
{
SelectedItems = items.ToList();
}
private void DeleteSelectedEmployees()
{
if (SelectedItems.Any())
{
GridData = GridData.Except(SelectedItems).ToList();
SelectedItems.Clear();
}
}
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Team { get; set; }
public override bool Equals(object obj) => obj is Employee e && e.EmployeeId == EmployeeId;
public override int GetHashCode() => EmployeeId.GetHashCode();
}
}
Hello,
I’ve run into a reproducible issue with the Blazor Grid in Adaptive mode. After the grid adapts to a smaller container and then the container is expanded again, the data rows scroll while the header remains fixed, so the header and data become detached.
I’m attaching three screenshots that show the sequence:
Steps to reproduce
Expected behavior
Header and data remain synchronized—when the grid is scrolled horizontally/vertically, both header and rows should scroll together.
Actual behavior
After returning from Adaptive to the standard layout, the header does not move with the rows when scrolling; it appears “detached”.
Notes
Please let me know if this is a known issue, if there’s a fix/workaround, or if you need any additional details.