Hello,
I want to do pagination / filtering using my service so I'm using a custom adaptor to get all my information. Right now my custom adaptor is very much based on your example with the exception that it uses a service to get the information. My custom adaptor looks like the following:
public class CraftAdaptor : DataAdaptor
{
private readonly ICraftService _craftService;
public CraftAdaptor(ICraftService craftService)
{
_craftService = craftService;
}
public IEnumerable<Craft> Crafts { get; set; }
public async override Task<object> ReadAsync(DataManagerRequest dm, string key = null)
{
IEnumerable<Craft> DataSource = await _craftService.GetCrafts(string.Empty);
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
// Sorting
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<Craft>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
for my grid, I have the following
<EjsGrid TValue="Craft" AllowGrouping="true" AllowPaging="true" Height="100%" Width="100%" AllowFiltering="true">
<EjsDataManager AdaptorInstance="@typeof(CraftAdaptor)" Adaptor="Adaptors.CustomAdaptor"></EjsDataManager>
<GridPageSettings PageCount="3" PageSizes="true"></GridPageSettings>
@*<GridGroupSettings ShowDropArea="@BelongsToAdministratorOrganization" Columns="@GroupedColumns"></GridGroupSettings>*@
<GridColumns>
<GridColumn Field=@nameof(Craft.OrganizationName) HeaderText="Organization" ></GridColumn>
<GridColumn Field=@nameof(Craft.Name) HeaderText="Name" AllowGrouping="false"></GridColumn>
<GridColumn Field=@nameof(Craft.NominalAltitude) HeaderText="Nominal Altitude" Format="N0" Type="ColumnType.Number" AllowGrouping="false"></GridColumn>
<GridColumn Field=@nameof(Craft.FieldOfView) HeaderText="Field of View" Format="N0" AllowGrouping="false"></GridColumn>
<GridColumn Field=@nameof(Craft.CraftType) HeaderText="Type" AllowGrouping="false"></GridColumn>
</GridColumns>
</EjsGrid>
The initial load is working and I can see the data showing on the grid. The problem comes when I try to group my information by a column. In my case, I only allow grouping for OganizationName, When I drag the column to the drop space, I get an exception and not really understand what the problem is. The exception is the following:
Unhandled exception rendering component: Unable to cast object of type 'Domain.Models.Craft' to type 'Syncfusion.EJ2.Blazor.Data.Group`1[Domain.Models.Craft]'.
System.InvalidCastException: Unable to cast object of type 'Domain.Models.Craft' to type 'Syncfusion.EJ2.Blazor.Data.Group`1[Domain.Models.Craft]'.
at Syncfusion.EJ2.Blazor.Grids.Internal.GroupModelGenerator`1.GenerateRows(IEnumerable data, Int32 startIndex)
at Syncfusion.EJ2.Blazor.Grids.Internal.GridContent`1.OnParametersSet()
at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.UpdateRetainedChildComponent(DiffContext& diffContext, Int32 oldComponentIndex, Int32 newComponentIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Any help is appreciated
thank you