It will be useful if the grid column state contains the Field parameter if such is specified.
This will make easier mapping the ColumnState entity to the actual column.
----
I have a column in the grid that is bound to a enum. The enum value names show up fine in the grid, but when exported, I get the underlying int value, which is incomprehensible to the users.
Thanks
---
ADMIN EDIT:
As a workaround you could generate the .xlsx file yourself. I'm attaching a sample project that allows you to do that. The relevant line of code is line 125 in Index.razor
---
Example Repo: https://github.com/benhysell/BlazorGridPagingIssue
Steps To Reproduce
I have a blazor grid with a large number of columns which I would like to have the width of the page and a horizontal scrollbar to be able to scroll through all of the columns.
According the the documentation I have found (https://demos.telerik.com/blazor-ui/grid/scrolling), setting the width of the grid to 100% and providing widths for the columns which exceed that of the width of the grid/page should cause the horizontal scrollbar to appear. Instead of doing this, however, the grid just expands horizontally to fit all of the columns, no matter what I try. In addition, it appears to be expanding the entire page horizontally to fit itself, as it is increasing the size of all of my bootstrap columns so that it fits within the bootstrap container.
Here is an example of a page containing a grid where I am experiencing this:
@page "/admin/users/manageusers"
@inherits ManageUsersBase
<h3>Manage Users</h3>
<WS7.Components.PDAuthorizeBase AllowedRoleIds="ManageAllUsers,ManageAssignedUsers" />
@if (this.Users == null)
{
<p><em>Loading...</em></p>
}
else
{
<div class="form-group">
<label for="UserSearch" class="col-form-label">Search</label>
<input id="UserSearch" class="form-control" type="search" aria-label="User Search" placeholder="Search" @bind-value="Filter" @bind-value:event="oninput" />
</div>
<TelerikGrid Data="@FilteredUsers" TItem="WS7.Engine.Models.ViewModels.ManageUsersViewModel" Height="600px" Width="100%" Pageable="true" PageSize="40" Sortable="true" Groupable="false"
FilterMode="GridFilterMode.FilterMenu" Resizable="true" Reorderable="true" OnEdit="EditUser" ScrollMode="@GridScrollMode.Scrollable">
<GridToolBar>
<GridCommandButton OnClick="(()=>AddUser())">
<span class="oi oi-plus"></span> Add
</GridCommandButton>
</GridToolBar>
<GridColumns>
<GridCommandColumn Width="100px">
<GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
</GridCommandColumn>
<GridColumn Field="UserName" Title="User Name" Width="500px" />
<GridColumn Field="Email" Title="Email" Width="500px" />
<GridColumn Field="FirstName" Title="First Name" Width="500px" />
<GridColumn Field="LastName" Title="Last Name" Width="500px" />
<GridColumn Field="AccountStatus" Title="Account Status" Width="500px">
<Template>
@{
string toolTip;
WS7.Engine.Models.ViewModels.ManageUsersViewModel user = context as WS7.Engine.Models.ViewModels.ManageUsersViewModel;
toolTip = "Account Status: " + user.AccountStatus;
toolTip += Environment.NewLine + "Active: " + user.Active.ToString();
toolTip += Environment.NewLine + "Email Confirmed: " + user.EmailConfirmed.ToString();
}
<div class="badge badge-pill badge-info">
<span class="oi oi-info" data-toggle="tooltip" data-placement="top" title="@toolTip"></span>
</div>
</Template>
</GridColumn>
@*<GridCommandColumn Width="90px">
<GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
</GridCommandColumn>*@
</GridColumns>
</TelerikGrid>
}
---
ADMIN EDIT
You can find some more details on the origin of the issue in the thread below and in the following Knowledge Base article, which also offers a few ideas for solutions to this browser behavior: https://docs.telerik.com/blazor-ui/knowledge-base/grid-bootstrap-flex-width-issue
---
I suggest adding a FieldExpression property to the GridColumn so a developer would not need to create view models and templates for simple transformations of the existing model's properties. The field expression would be used for filtering and sorting as well. Its type would be Func<T, object> or Expression<Func<T, object>>.
<TelerikGrid Data="@Persons">
<GridColumns>
<GridColumn FieldExpression="@(p => p.FirstName + " " + p.LastName)" />
</GridColumns>
</TelerikGrid>
Hi,
I am using a grid on a data structure that has nested properties inside. Previously, I was able to do this which worked fine: (notice the first 2 colums)
<TelerikGrid Data="@PackedInfo.PackedParts" Height="100%">
<GridColumns>
<GridColumn Field=@nameof(PackedPart.Part.PartNo) Title="Part no" />
<GridColumn Field=@nameof(PackedPart.Part.PartDescription) Title="Description" />
<GridColumn Field=@nameof(PackedPart.UnitWeightG) Title="Substance Weight" />
<GridColumn Field=@nameof(PackedPart.FlashPointCentigrade) Title="Flash point" />
<GridColumn Field=@nameof(PackedPart.Pg) Title="PG" />
<GridColumn Field=@nameof(PackedPart.Qty) Title="PG" />
</GridColumns>
</TelerikGrid>
I recently upgraded to the latest version (Telerik.UI.for.Blazor (2.29.0) and noticed that the first 2 fields are no longer displaying. I fixed this, by specifying the field names as string values:
<TelerikGrid Data="@PackedInfo.PackedParts" Height="100%">
<GridColumns>
<GridColumn Field="Part.PartNo" Title="Part no" />
<GridColumn Field="Part.PartDescription" Title="Description" />
<GridColumn Field=@nameof(PackedPart.UnitWeightG) Title="Substance Weight" />
<GridColumn Field=@nameof(PackedPart.FlashPointCentigrade) Title="Flash point" />
<GridColumn Field=@nameof(PackedPart.Pg) Title="PG" />
<GridColumn Field=@nameof(PackedPart.Qty) Title="PG" />
</GridColumns>
</TelerikGrid>
I have also tried using @nameof(Part.PartNo) but that didn't work either. Only providing nested properties as string values works. This should not be the intended behaviour i'm sure?
regards,
Chris Nateghi
I have a reset all button that clears a grid of all column, filter, sorts etc.
I need it to also reset any searchbox criteria. I can easily clear the searchbox of it's value using javascript, but this does not then trigger the searchbox to reset the grid.
---
TELERIK EDIT
The officially supported way to clear the GridSeachBox is through the Grid state. You can see an example in the Grid SeachBox documentation.
A possible workaround for old versions is to clear the search textbox with JavaScript and to trigger its input event:
@inject IJSRuntime js
<TelerikGrid Data="@GridData"
Pageable="true"
Sortable="true"
Class="custom-grid-class">
<GridToolBarTemplate>
<GridSearchBox />
<TelerikButton Icon="@SvgIcon.X" OnClick="@OnClearButtonClick"></TelerikButton>
</GridToolBarTemplate>
<GridColumns>
<GridColumn Field="@nameof(SampleModel.Name)" />
<GridColumn Field="@nameof(SampleModel.Description)" />
</GridColumns>
</TelerikGrid>
<script suppress-error="BL9992">//
function clearSearch() {
// locate the searchbox of the Grid
const input = document.querySelector(".custom-grid-class .k-grid-search input");
// clear the value of the input
input.value = "";
// dispatch the input event in order to force the Grid event binding to trigger the filtering
input.dispatchEvent(new Event('input', {bubbles: true} ));
}
//</script>
@code {
private List<SampleModel> GridData { get; set; } = new();
private async Task OnClearButtonClick()
{
await js.InvokeVoidAsync("clearSearch");
}
protected override void OnInitialized()
{
for (int i = 1; i <= 50; i++)
{
GridData.Add(new SampleModel()
{
Id = i,
Name = $"{(char)(64 + i % 26 + 1)}{(char)(64 + i % 26 + 1)} {i}",
Description = $"{(char)(123 - i % 26 - 1)}{(char)(123 - i % 26 - 1)} {i}"
});
}
}
public class SampleModel
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
}
}
I want the grid to be able to resize all the columns (or only certain columns) to fit their data, when the data loads, without the user having to double click the border between them.
---
ADMIN EDIT
Automatic application of the auto fitting will come with a flicker, and that's why it was declined as a feature originally. In Blazor we have a detachment between code and when exactly something is rendered. So, we have no way to trigger the resizing logic immediately after the columns content is rendered. The events that are available will cause a flicker and can cause a performance hit - both for the browser and also by raising StateChanged multiple times.
Another caveat is how would this be exposed for configuration - should it work for all columns at once, or only for certain columns (how to control for which ones), how to control which data-related events should invoke this logic (or should it happen super often on any event). Exposing such configuration is likely to lead to a property hell type of situation.
Perhaps a way to get this would be to provide API on the grid to invoke that functionality that you can call as required by your logic and UX: https://feedback.telerik.com/blazor/1513384-programmatically-invoke-fit-to-width-functionality-for-the-grid-columns.
Nevertheless, we will keep this open to monitor for feedback, what is requested, interest and how people would want it exposed. Leave your comments and preferences here.
---
AutoFitting all columns should not leave blank space in the Grid, the last column should take the available space.
This functionality might be triggered by a setting a bool parameter to true.
Problem:
Grid exports columns as 0 width unless Grid column widths are specified in px. This is a terrible experience for users, and specifying grid width in px is terrible when you have users that can be using phones or 4k screens. Managing Grid for different screen sizes is already hard enough!
Solution 1: (Good)
The grid should export a default (64px) width for columns that aren't specified in px. Inexperienced Excel users are lost when columns are collapsed, but can easily resize columns as needed when each one is visible!
Solution 2: (Better)
Calculate a width - like [(rem value)*10]px. Even if it isn't perfect it will go a long way to creating something visually pleasing on initial open in Excel.
Right now you can create a template in the grid to display text from a list based on the foreign key in the grid data. For example, if your database has a table user list and a table role. The Role table has an integer Id primary key column and a text Description column. The user table has a foreign key integer column that is the Role Id. You can bring all the data over when you call up the data (flattening the data) or you can just bring over the foreign key integer value for the role and then create templates.
The situation is described here:
https://docs.telerik.com/blazor-ui/knowledge-base/grids-foreign-key
When you do not flatten the data, you would need to retrieve the role collection and then reference that data in templates in the grid. You need a template for the grid itself, a template for filtering, and a template for the grouping. Maybe more that I am not finding?
What would be great is if you could simply set the foreign key collection for the column and not have to create any templates. You would have to also set what the Id and display text fields are on the collection also so the grid would know what data to use for finding and displaying the desired data. You could require a standard collection with standard field names and then we would have to project the values into it from our other collections using linq.
When you shrink a Grid column, ellipsis is rendered to represent the clipped text. However, at some point of resizing the Column menu and Filter menu indicators are overlapping the Grid column header text.
==========
ADMIN EDIT
==========
In the meantime, a possible workaround would be to use some custom CSS to add right padding to the k-link span, so it does not get overlapped by the column menu icon. That padding should be approximately as wide as the span holding the column menu icon. You can also set a custom CSS class to the Grid through its Class parameter to make sure you are styling this exact instance of the Grid and not all instances on the page/app. The example below demonstrates how to achieve the described approach.
<style>
.my-grid .k-link {
padding-right: 40px;
}
</style>
<TelerikGrid Data="@MyData"
Class="my-grid"
Pageable="true"
PageSize="5"
FilterMode="@GridFilterMode.FilterMenu"
Sortable="true"
Resizable="true"
ShowColumnMenu="true">
<GridColumns>
<GridColumn Field="@(nameof(SampleData.Id))" Width="80px" />
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name"/>
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" />
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" />
</GridColumns>
</TelerikGrid>
@code {
public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData
{
Id = x,
Name = "name " + x,
Team = "team " + x % 5,
HireDate = DateTime.Now.AddDays(-x).Date
});
public class SampleData
{
public int Id { get; set; }
public string Name { get; set; }
public string Team { get; set; }
public DateTime HireDate { get; set; }
}
}