Telerik Forums
UI for Blazor Forum
1 answer
44 views

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!



Svetoslav Dimitrov
Telerik team
 answered on 11 Mar 2024
1 answer
28 views
I need to know when the grid has been rendered. Is there a way?
Hristian Stefanov
Telerik team
 answered on 11 Mar 2024
1 answer
22 views
Looking for a solution to expand the previous expanded DetailTemplate after a grid rebind.  The data for the grid is updated from a click event within the DetailTemplate and need the grid updated and the expanded row to either stay expanded or re-expand after the grid rebind.
Tsvetomir
Telerik team
 answered on 07 Mar 2024
1 answer
66 views

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".

 

 

Dimo
Telerik team
 updated answer on 07 Mar 2024
1 answer
37 views

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?

Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
 answered on 01 Mar 2024
1 answer
22 views
My scenario is that I have a grid of User. 
a User has Roles. 

I have a column that I have used the <Template> to display a chip of each Role a User has. 


The FilterTemplate does not have a solution to filter this collection out of the box. 
Have you solved this or similar? Please share any helpful feedback here as I am blocked on this task. 

I would prefer not to filter on a concatenated string of the users roles, as if I click the filter checkbox 'Admin' it would show results for any role that had Admin in it's name. 

If you used the OnRead event, when did you apply your filter and how?  

Thanks so much for your feedback on how you've solved this for your use case. 
 
Nadezhda Tacheva
Telerik team
 answered on 01 Mar 2024
1 answer
974 views

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

Dimo
Telerik team
 updated answer on 01 Mar 2024
1 answer
30 views

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.

Yanis
Top achievements
Rank 1
Iron
 answered on 29 Feb 2024
0 answers
30 views

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!

1 answer
24 views

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; }
	}
}


Dimo
Telerik team
 answered on 23 Feb 2024
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?