Hi,
I'm attempting to do something that is probably dumb/unsupported. We have a paginated grid in our UI that we want to include a joined model in.
Example:
public class Item { [Key] public Guid ItemId{ get; set; } = Guid.NewGuid(); public Guid? LatestLogId { get; set; } } public class ItemLog { [Key] public Guid ItemLogId{ get; set; } public Guid ItemId{ get; set; } [ForeignKey("ItemId")] public Item? Item { get; set; } [MaxLength(250)] public string Message { get; set; } = null!; }
We use 'LatestLogId' in order to know what ItemLog to 'include' in the results in the UI
I'm trying to project it into a Dto that includes both the Item and the LatestLog but running into some trouble calling 'ToDataSourceResultAsync' with that IQueryable<Dto>
public async Task<DataSourceResult> GetItemReportPage(DataSourceRequest pageRequest, Guid staffId,
bool includeAll = false)
{
var baseQuery = _appContext.Items
.AsQueryable();
if (!includeAll)
{
baseQuery = baseQuery.Where(x => x.CreatedBy== staffId);
}
var query= baseQuery.Select(item => new ItemWithLatestLogDto
{
LatestLog = _appContext.ItemLogs.FirstOrDefault(x => x.ItemLogId== request.LatestLogId)
})
.AsNoTracking();
var dataSourceResult = await query.ToDataSourceResultAsync(pageRequest);
return dataSourceResult;
}
When calling that I get an error that is something like this:
System.InvalidOperationException: The LINQ expression 'DbSet<Item>()
.Where(n => n.CreatedById== __staffId_0)
.OrderByDescending(n => new ItemWithLatestLogDto{ LatestLog = DbSet<ItemLog>()
.Where(r => (Guid?)r.ItemLogId== n.LatestLogId)
.FirstOrDefault() }
.CreatedDateTimeUtc)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0&)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.System.Collections.IEnumerable.GetEnumerator()
at Telerik.DataSource.Extensions.QueryableExtensions.Execute[TModel,TResult](IQueryable source, Func`2 selector)
at Telerik.DataSource.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, Func`2 selector)
at Telerik.DataSource.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request)
The Dto looks like this:
public class ItemWithLatestLogDto: Item
{
public ItemLog? LatestLog { get; set; }
public NewFileRequestWithLatestLogDto()
{
}
}
Is this a use-case supported by the method or do I need to find a different way of accomplishing this?
Thanks!
I'm having trouble finding the cause of why the display has changed and the paging control is cutting off the value. I can't see the difference from the Telerik doc examples.
or ...
The width of the browser window or resolution doesn't have any effect.
We are using the "_content/Telerik.UI.for.Blazor/css/kendo-theme-bootstrap/all.css".
Hi, i use Grid.AutoFitAllColumnsAsync() to resize column width based on column content.
Now, this method resize also non resizable columns (Resizable="false")
I would like to apply autofit only on resizable columns, how to solve?
I would use AutoFitColumnsAsync() method but i need a generic way to apply it excluding non resizable columns.
There is a way to read from code the Resizable property of columns?
Hello,
I don't want to add any GridCommandButton into the Grid's Layout.
For example I have implemented a ribbon on my page and there I have a button "Add Entry". Is it possible to achieve the same functionality from that button I have mentioned as when the Add GridCommandButton with the attribute Command="Add" is added to the grid layout in the toolbar?
Best regards,
Cipri
Hi.
I'm facing a embarassing problem about browser compatibility of DataGrid.
I want to load my data on demand when the user scroll.
For that i have choosed a DataGrid and i have implemented a behavior like a "scroll infini" which authorize the user to moove his scrollbar anywhere in the grid.
Everything work but ... on Mozilla Firefox, the Grid work like a incremential grid and not a infinite scroll grid. Even if the code is exactly the same.
On this first screenshot you can see the scrollbar of the grid with Mozilla Firefox (which reduce when you scroll).
On the second one screenshot, I am on Microsoft Edge (on the same page and same URL) but there the behavior is correct (the scroll bar is small and i can move it anywhere i want even if the data is not yet loaded).
The DataGrid work well with browser that use Chromium kernel (Microsoft Edge, Opera and Chromium for example).
Do you have any idea ?
Thanks.
Best regards,
Yanis.
Issue Description: I'm encountering challenges with dynamically positioning the command column within the Telerik Blazor DataGrid while using a single grid component for two pages. Each page utilizes the same grid component but may have different sets of columns generated dynamically. Despite this setup, I'm unable to ensure that the command column consistently appears at the last position in the grid on both pages.
Background:
In my application, I've implemented Telerik Blazor's DataGrid component to display tabular data across multiple pages. To streamline development and improve code maintainability, I've opted to use a single grid component shared between two pages. Each page may have a different set of columns generated dynamically based on the specific requirements of the page. Additionally, the data source for the grid is an ExpandoObject
, and I'm using a loop to dynamically generate columns.
Current Approach: My current approach involves dynamically generating columns using a loop for each page's specific requirements. However, due to the shared nature of the grid component and the dynamic nature of the data source, I'm experiencing difficulties in ensuring that the command column, which contains actions like edit, delete, etc., is consistently positioned at the last column on both pages.
Expected Behavior:
I expect to have precise control over the position of the command column within the DataGrid, even when using a single grid component shared between two pages and dynamically generating columns with ExpandoObject
as the data source. Regardless of the page being accessed, the command column should always appear at the last position in the grid, providing users with a consistent interface for interacting with the data.
Request for Assistance:
I'm seeking assistance from the Telerik community for guidance, insights, or potential workarounds on how to achieve the desired behavior of positioning the command column as the last column in the DataGrid consistently across two pages, even when utilizing a shared grid component and dynamically generating columns with ExpandoObject
as the data source.
Any assistance or suggestions would be highly appreciated. Thank you for your support!
After editing a cell, if I press ENTER it automatically starts editing the cell below; if I press TAB it automatically starts editing the cell at the right:
After pressing TAB:
I need to deactivate that behavior: Press ENTER or TAB should update the target cell and stop editing any other cell:
I tried using Navigable = "false" with no results. How can I achieve this?
This is the example code:
<TelerikGrid Data="Items" Navigable="false" EditMode="GridEditMode.Incell" Width="400px">
<GridColumns>
<GridColumn Field="Name" Title="Name" />
<GridColumn Field="Phone" Title="Phone" />
<GridColumn Field="Address" Title="Address" />
</GridColumns>
</TelerikGrid>
@code {
private List<Item> Items = new()
{
new Item {Name = "User1", Phone = "1111111", Address = "Address1" },
new Item {Name = "User2", Phone = "2222222", Address = "Address2" },
new Item {Name = "User3", Phone = "3333333", Address = "Address3" }
};
private class Item
{
public string Name { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
}
}