Hi,
I've noticed some odd behaviour where the OnRead event is being called twice. Initially I thought it was my code, but I've got to a bizarre example where having two Console.WriteLine statements causes the repeated call, but having one doesn't!
In my testing with more code in the method it hasn't been consistent, so I'm not sure if it's a timing/threading issue. I have tested with the following:
My test code looks like this:
@layout EmptyLayout
@page
"/testgrid"
<TelerikGrid Data=@GridData TotalCount=@Total
Pageable=
true
PageSize=15
OnRead=@ReadItems>
<GridColumns>
<GridColumn Field=@nameof(Employee.Id) Title=
"ID"
/>
<GridColumn Field=@nameof(Employee.Name) Title=
"Name"
/>
</GridColumns>
</TelerikGrid>
@code {
public
List<Employee> GridData {
get
;
set
; }
public
int
Total {
get
;
set
; } = 0;
protected
async Task ReadItems(GridReadEventArgs args)
{
Console.WriteLine(
"ReadItems 1"
);
// Remove this line and ReadItems is only called once!!!
Console.WriteLine(
"ReadItems 2"
);
// Adding this makes no difference
//await Task.Delay(1);
}
public
class
DataEnvelope
{
public
List<Employee> CurrentPageData {
get
;
set
; }
public
int
TotalItemCount {
get
;
set
; }
}
public
class
Employee
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
}
}
Any help appreciated!
Thanks.
Hi
I have a question regarding the telerik grid component particularly the hierarchy. Is it possible to open a hierarchy programmatically? For example:
I have my grid with information. Every row have more information to show. Those are stored in a hierarchy level to this row. Can I, instead of clicking the '+'-button in the row, just open it with with a method that i call e.g. in another button?
I want to make the rows clickable, i saw in the forum that this isn't yet supported for the grid. Now, I'm placing a div-Tag in the DetailTemplate of this row, and give that div a onclick-Attribute. The method the div invokes, should open the row for me respectively show the hierarchy of this row.
Is this possible?
thanks for your support.
regards
Ali Shala
@using ClientApp.Shared
@inject HttpClient Http
<TelerikGrid Data=@forecasts Height="550px"
Pageable="true" Sortable="true"
PageSize="20" Groupable="true">
<GridColumns>
<GridColumn Field="Date">
<Template>
@((context as WeatherForecast).Date.ToString("dddd, dd MMM yyyy"))
</Template>
</GridColumn>
<GridColumn Field="TemperatureC" Title="Temp. C" />
<GridColumn Field="TemperatureF" Title="Temp. F" />
<GridColumn Field="Summary" />
</GridColumns>
</TelerikGrid>
@code {
//List<WeatherForecast> forecasts { get; set; } = new List<WeatherForecast>(); // Works fine!
List<WeatherForecast> forecasts { get; set; } //Need to sort a field to show the rows
protected override async Task OnInitializedAsync()
{
//forecasts = new List<WeatherForecast>(); //this helps
forecasts = await Http.GetJsonAsync<List<WeatherForecast>>("WeatherForecast");
//these do not help
//await Task.Delay(200);
//StateHasChanged();
}
}
@GridEditMode.Incell mode does not update automatically on row change when an editortemplate is used, as below
<GridColumn Field=@nameof(ProjectRankingInfo.Ranking.Option2) Title="@Option2Title" Width="120px" Filterable="false">
<EditorTemplate>
@{
currentItem = context as ProjectRankingInfo.Ranking;
<TelerikNumericTextBox Max="10" Min="0" Step="1" @bind-Value=@currentItem.Option2 />
}
</EditorTemplate>
</GridColumn>
one must click the update button for the update to occur,
Incell works fine and updates on row change for simple grid columns
ADMIN EDIT: SOLUTION: Read the details in the following article: https://docs.telerik.com/blazor-ui/components/grid/editing/incell#notes
ADMIN EDIT: this thread is rather long and I am adding the workaround offered by René here:
<TelerikGrid Data="@GridData" OnUpdate="@UpdateHandler"> ... </TelerikGrid>Hi there,
Is it possible to have multi-column headers for the data grid, like we have in Kendo grid.
if so, what would be the ETA?
Thanks,
Deepa
Would be helpful to have the feature of copying selected row to the clipboard.
The copy format could be CSV or just tabbed delimiter.
---
ADMIN EDIT
In the meantime, you can consider your own JS-based solution (example StackOverflow thread) and integrate them on a command button in the grid or in the row context menu.
---
I have a simple Grid with custom detail template
<Telerik.Blazor.Components.TelerikGrid Data="@GridData" FilterMode="Telerik.Blazor.GridFilterMode.FilterRow" >
<GridColumns>
<Telerik.Blazor.Components.GridCheckboxColumn Title="Selected"></Telerik.Blazor.Components.GridCheckboxColumn>
<Telerik.Blazor.Components.GridColumn Title="Name" Filterable="true" Field="@nameof(GridItem.Text)"></Telerik.Blazor.Components.GridColumn>
<Telerik.Blazor.Components.GridColumn Field="@nameof(GridItem.Date)" Filterable="true" Title="Date"></Telerik.Blazor.Components.GridColumn>
<Telerik.Blazor.Components.GridColumn Field="@nameof(GridItem.Id)" Filterable="true" Title="Id"></Telerik.Blazor.Components.GridColumn>
<Telerik.Blazor.Components.GridColumn Field="@nameof(GridItem.ParentIdValue)" Filterable="true" Title="Parent Id"></Telerik.Blazor.Components.GridColumn>
<Telerik.Blazor.Components.GridColumn Field="@nameof(GridItem.HasChildren)" Filterable="true" Title="Has Children"></Telerik.Blazor.Components.GridColumn>
</GridColumns>
<DetailTemplate>
<div>Custom Template</div>
</DetailTemplate>
</Telerik.Blazor.Components.TelerikGrid>
And here is what it looks like. Filters are moved one column to the left. When I remove DetailTemplate everything is ok.
When a column is displayed conditionally, it's order is not preserved. In the code sample below, the ProductId column is the first column in the grid. When you click the checkbox to hide the column, it is removed. Click the checkbox again and the column reappears but it is the last column in the grid.
ADMIN EDIT: At the end of this post there is an attachment with a workaround through a custom column chooser.
<input type="checkbox" @onchange="@ToggleColumn" />
<TelerikGrid Data=@GridData>
<GridColumns>
@if (ShowColumn)
{
<GridColumn Field=@nameof(Product.ProductId) Title="Id" />
}
<GridColumn Field=@nameof(Product.ProductName) Title="Product Name" />
<GridColumn Field=@nameof(Product.UnitPrice) Title="Unit Price">
<Template>
@(String.Format("{0:C2}", (context as Product).UnitPrice))
</Template>
</GridColumn>
</GridColumns>
</TelerikGrid>
@code {
public IEnumerable<Product> GridData { get; set; }
bool ShowColumn = true;
protected override void OnInitialized()
{
List<Product> products = new List<Product>();
for (int i = 0; i < 20; i++)
{
products.Add(new Product()
{
ProductId = i,
ProductName = "Product" + i.ToString(),
UnitPrice = (decimal)(i * 3.14)
});
}
GridData = products.AsQueryable();
}
private void ToggleColumn(ChangeEventArgs args)
{
ShowColumn = (bool)args.Value;
}
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
}
}
Hi !
How can i hide some columns on small device ?
Telerik.Blazor.Components.GridColumn.Class does not exist ?
Regards,
--------
ADMIN EDIT
This will be done through the Visible parameter of the column. You can bind it to a flag that hides the column for the desired scenarios (resolution, user settings, etc.). The new feature we provide to facilitate this will be a MediaQuery component that lets you have an easy flag in the C# code based on the media query for the desired resolution. There will be a demo how to use it with the grid columns when the 2.23.0 release is live. With this approach you will still use a CSS media query, but this will give you more flexibility to use it in more functionality than just the grid columns, and will avoid adding extra properties to the column.
--------
Please add a feature to export the grid to a PDF file.
---
ADMIN EDIT
We have made two examples you can use for the time being to get a PDF document from the grid:
---
Is there any way to default the values that are used when I create a new row?
So for example, I have a row where I want to default a date to Jan 1st of the following year. However, when I add the row, it adds nulls to all fields and the date shows up as 1 Jan 1900 and there's a lot of fiddly clicking to set the right date.
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.