Mewriick / Blazor.FlexGrid

GridView component for Blazor
MIT License
199 stars 35 forks source link

Any way to refresh data using the LazyLoadedTableAdapter #78

Closed larshg closed 4 years ago

larshg commented 4 years ago

Hi @Mewriick

I'm currently trying to implement the use of your quite nice flexgrid - serverside blazor.

However, I have another process which occasionally adds new entries to the DB and I would like to update the view using a timer, but I can't find a way to force the reload.

Also, I tried using the AllowCreateItem, but it makes exceptions as soon as I add the line:

FROM [LogMessages] AS [l]
ORDER BY [l].[Timestamp] DESC
OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY
Microsoft.EntityFrameworkCore.Query: Error: An exception occurred while iterating over the results of a query for context type 'EngskovLogningv2.Data.EngskovDataContext'.
System.InvalidOperationException: Invalid attempt to call ReadAsync when reader is closed.
   at Microsoft.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()

System.InvalidOperationException: Invalid attempt to call ReadAsync when reader is closed.
   at Microsoft.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 18509.1219ms 101 
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.0\System.IO.MemoryMappedFiles.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Invalid attempt to call ReadAsync when reader is closed.

System.InvalidOperationException: Invalid attempt to call ReadAsync when reader is closed.
   at Microsoft.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at EngskovLogningv2.Services.LogMessageService.GetTablePageData(RequestOptions requestOptions, IReadOnlyCollection`1 filterDefinitions) in E:\Code\CSharpBlazor\EngskovLogningV2\EngskovLogningv2\Services\LogMessageService.cs:line 25
   at Blazor.FlexGrid.DataSet.LazyTableDataSet`1.GoToPage(Int32 index)
   at Blazor.FlexGrid.Components.GridViewInternal.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'TOxrKWpcHA9xRvmwF0kHrLj3n-9GOXqUIFb-9C_RMo0'.

System.InvalidOperationException: Invalid attempt to call ReadAsync when reader is closed.
   at Microsoft.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at EngskovLogningv2.Services.LogMessageService.GetTablePageData(RequestOptions requestOptions, IReadOnlyCollection`1 filterDefinitions) in E:\Code\CSharpBlazor\EngskovLogningV2\EngskovLogningv2\Services\LogMessageService.cs:line 25
   at Blazor.FlexGrid.DataSet.LazyTableDataSet`1.GoToPage(Int32 index)
   at Blazor.FlexGrid.Components.GridViewInternal.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
The thread 0x6cdc has exited with code 0 (0x0).

In both cases I would like a function to refresh "current page" - often the latest entries added.

Mewriick commented 4 years ago

Hello @larshg

currently you cannot force reload FlexGrid due to functionallity in OnParameterAsync. I will think about it and how to solve this kind of problem with refreshind FlexGrid data.

larshg commented 4 years ago

@Mewriick Thanks

I tried to search through the source to figure out how the "next page" etc is made - wouldn't be possible to make a "navigate to current page / refresh" - or is it due to some variables update, which triggers the refresh? ie. setting the "CurrentPage" to 1 when it is already 1 doesn't trigger it?

Mewriick commented 4 years ago

@larshg

The problem now is that you must call some method on object LazyTableDataSet<TItem> which is not provided to the outside world. You only have table data adapter which internally create this data set object. I have to provide some public API for force refresh.

Mewriick commented 4 years ago

@larshg

Version 0.11.0 contains new feature which you can use for refreshing grid view. See the wiki