Hello,
I am new to your Blazor UI components. Please provide a link for exporting a grid to excel.
Thanks,
Earl
I would like to be able to do something like
<GridCommandColumn>
@{
context as MyModel;
if(context.ShowButton)
{
<GridCommandButton>Todo</GridCommandButton>
}
}
</GridCommandColumn>
---
ADMIN EDIT
See the thread below for a way to implement this right now with your own buttons in a "regular" column and the grid state.
---
Hello,
I am currently fiddling around with the Blazor UI, mainly the grid. I was wondering if it is possible to configure the grid to automatically fit the columns to the contents they have?
Meaning that the width of the header and the content cells of a given column are automatically set to a value which best fits either the cells content or the header title (depending on what takes up more space).
Best Regards,
Karl
With OnRead, AllPages cannot be exported because the grid Data only has the current page: https://docs.telerik.com/blazor-ui/components/grid/export/excel#notes:
If you are using the OnRead event, only the current page of data will be exported, because that's all the grid has at the time of the export action.
I load my data via "OnRead", because i need to implement pagination by myself, and I would like the export option to work with that too.
I need the ability to show or hide command buttons based on a row's property.
I am aware that I can just cancel commands, but in my opinion, a command button should not even be shown when the command can't or shouldn't be executed on a row.
Unfortunately, I was unable to find a way to access the "context" (the instance) in a TelerikGridCommandColumn the same way you're able to in a normal TelerikGridColumn.
---
ADMIN EDIT
You can Vote for and Follow this request for a follow up on providing the model as context to the command column: https://feedback.telerik.com/blazor/1461283-pass-the-model-context-to-command-button. At the moment, conditional command buttons are possible in a "normal" column through the grid state, the page above shows an example.
---
Hello,
Do you have any sample for custom group Header template.
e..g. To calculate the value of the column based on the other fields.
---
ADMIN EDIT
---
Once aggregates for all fields are exposed, we will need to provide an option to align them with the corresponding columns. This can be achieved through a GroupHeaderColumnTemplate which is targeted in a separate request.
Grid column header and content alignment (horizontal +Vertical)
---
ADMIN EDIT
For the time being, this is possible through the CellRender event, see below in the thread for an example.
---
I want to be able to enter numbers and the grid to filter numeric fields too according to those numbers. Enums would be nice too.
**Admin Edit**
The feature request will be researched and evaluated. It contradicts to our datasource filtering logic that relies on the type of the fields. Thus, it is highly possible that we will handle the task through a knowledge base example.
**Admin Edit**
---
ADMIN EDIT: Check the source code and comments in it from the following demo to see how to bind the grid to a DataTable: https://demos.telerik.com/blazor-ui/grid/data-table. You can also examine it offline - the entire demos project is available in the "demos" folder of your installation
The sample code snippet below will let the grid show data, but will not enable complex operations like filtering and sorting. Review the demo linked above for more details on the correct approach.
---
I would like to be able to supply a DataTable with an arbitrary amount of columns to the grid and display them all without declaring them all. This should also allow paging, sorting, filtering. At the moment binding to a DataTable is not supported, only IEnumerable collections are.
At the moment, here's the closest I can get, sorting and filtering throw errors so they are disabled.
@
using
System.Data
@
using
Telerik.Blazor
@
using
Telerik.Blazor.Components.Grid
<button
class
=
"btn btn-primary"
@onclick=
"@LoadData"
>Load Data</button>
@
if
(@d !=
null
)
{
<TelerikGrid Data=@d.AsEnumerable() TItem=
"DataRow"
Sortable=
"false"
Filterable=
"false"
Pageable=
"true"
PageSize=
"3"
Height=
"400px"
>
<TelerikGridColumns>
@
foreach
(DataColumn col
in
d.Columns)
{
<TelerikGridColumn Field=
"@col.ColumnName"
Title=
"@col.ColumnName"
>
<Template>
@((context
as
DataRow).ItemArray[col.Ordinal].ToString())
</Template>
</TelerikGridColumn>
}
</TelerikGridColumns>
</TelerikGrid>
}
@functions {
DataTable d =
null
;
void
LoadData()
{
d = GetData();
}
public
DataTable GetData()
{
DataTable table =
new
DataTable();
table.Columns.Add(
"Product"
,
typeof
(
string
));
table.Columns.Add(
"Price"
,
typeof
(
double
));
table.Columns.Add(
"Quantity"
,
typeof
(
int
));
table.Columns.Add(
"AvailableFrom"
,
typeof
(DateTime));
table.Rows.Add(
"Product 1"
, 10.1, 2, DateTime.Now);
table.Rows.Add(
"Product 2"
, 1.50, 10, DateTime.Now);
table.Rows.Add(
"Product 3"
, 120.66, 5, DateTime.Now);
table.Rows.Add(
"Product 4"
, 30.05, 10, DateTime.Now);
return
table;
}
}
ADMIN EDIT: The following knowledge base article has been updated to explain how to use nested models: https://docs.telerik.com/blazor-ui/knowledge-base/grid-bind-navigation-property-complex-object
At the moment, you must use flat models with primitive types for binding the grid. If you don't, the data source operations break and they can't even display "nested" values. Examples here and here.
I would like to be able to use my complex models so I can point a grid's column to a field like MyModel.MyNestedModel.MyPrimitiveField
My be related to binding to a data table and dynamic expando.
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.
---
Please add an attribute to Blazor GridColumn which allows to easily format data with the default .NET standard formats
e.g. <GridColumn Field="@(nameof(Item.Price))" Title="Price" Format="0#.##" />
It's a little bit annoying always having to define a template for this purpose.
I know that I can bind the PageSize property to a variable, but then I have to build a dropdown with the available page sizes in a separate control. Are there plans to integrate a page size selection into the existing paging controls? Perhaps a PageSizes property that takes an array of integers.
Example:
PageSizes = "[10, 25, 50, 100]"
These would then be converted into a dropdown integrated into the existing paging controls on the grid.
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;
}
}
How would you remove the icon to expand a detail grid only for certain rows? Some rows will not have detail data and should not be expandable.
---
ADMIN EDIT
As suggested by Joel, you can use the RowRender event and a bit of CSS to hide the button. Here is a Knolwdge Base article that shows a fully runnable sample: https://docs.telerik.com/blazor-ui/knowledge-base/grid-conditional-expand-button.
void OnRowRenderHandler(GridRowRenderEventArgs args)
{
OrgUnit item = args.Item as OrgUnit;
args.Class = item.Children.length ? "has-children" : "no-children";
}
tr.no-children .k-hierarchy-cell *{
display:none !important;
}