GridForeignColumn Not working

GridForeignColumn Not working


My Grid Is 

<SfGrid ID="Grid" TValue="MasterRolePermission"

        AllowSorting="true" AllowFiltering="true" AllowPaging="true"

        Toolbar="@(new List<string>() { "Add", "Edit", "Delete" })">

    <SfDataManager AdaptorInstance="@typeof(MasterDataAdapter<MasterRolePermission>)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>

    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog" ShowDeleteConfirmDialog="true"></GridEditSettings>

    <GridEvents OnActionFailure="Failer" TValue="MasterRolePermission"></GridEvents>

    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>

    <GridColumns>

        <GridColumn Field=@nameof(MasterRolePermission.Id) Visible="false" IsPrimaryKey="true"></GridColumn>

        <GridForeignColumn Field=@nameof(MasterRolePermission.Controller) TValue="MasterRoleController" HeaderText="Controller" ForeignKeyValue="DisplayName" ForeignKeyField="ControllerId">

            <SfDataManager AdaptorInstance="@typeof(MasterDataAdapter<MasterRoleController>)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>

        </GridForeignColumn>

        <GridColumn Field=@nameof(MasterRolePermission.Read)></GridColumn>

        <GridColumn Field=@nameof(MasterRolePermission.Create)></GridColumn>

        <GridColumn Field=@nameof(MasterRolePermission.Update)></GridColumn>

        <GridColumn Field=@nameof(MasterRolePermission.Delete)></GridColumn>

        <GridColumn Field=@nameof(MasterRolePermission.Approve)></GridColumn>

        <GridColumn Field=@nameof(MasterRolePermission.OnlySelf)></GridColumn>

    </GridColumns>

</SfGrid>


Model  Class is 

 public class MasterRolePermission : LtModel

    {


        public bool Create { get; set; }

        public bool Read { get; set; }

        public bool Update { get; set; }

        public bool Delete { get; set; }

        public bool Approve { get; set; }

        public bool OnlySelf { get; set; }

        public int RoleId { get; set; }

        public virtual MasterRole Role { get; set; }

        public int ControllerId { get; set; }

        public virtual MasterRoleController Controller { get; set; }



    }


public class MasterRoleController : LtModel

    {

        public String DisplayName { get; set; }

        public string IconClass { get; set; }

        public string Route { get; set; }


        [InverseProperty("Controller")]

        public virtual ICollection<MasterRolePermission> Permissions { get; set; } = new HashSet<MasterRolePermission>();

    }



Error is 



System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.Data.QueryableOperation.GetColumnType[T](IQueryable`1 dataSource, String filterString, Type type)

   at Syncfusion.Blazor.Data.QueryableOperation.PredicateBuilder[T](IQueryable`1 dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)

   at Syncfusion.Blazor.Data.QueryableOperation.PerformFiltering[T](IQueryable`1 dataSource, List`1 whereFilter, String condition)

   at Syncfusion.Blazor.DataOperations.PerformFiltering[T](IEnumerable`1 dataSource, List`1 whereFilter, String condition)

   at Syncfusion.Blazor.Grids.Internal.GridUtils.GetForeignData(GridColumn column, Object data, Object fkData)

   at Syncfusion.Blazor.Grids.Internal.RowModelGenerator`1.RefreshForeignKeyRow(Row`1 row, Object item)

   at Syncfusion.Blazor.Grids.Internal.RowModelGenerator`1.GenerateRow(Object item, Int32 index)

   at Syncfusion.Blazor.Grids.Internal.RowModelGenerator`1.GeneratorRows(IEnumerable`1 data, Int32 startIndex)

   at Syncfusion.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()

Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'LrDgw6Irp3oXSN0dFj8fRuUx6NkFo79cxh6bovnicwQ'.


1 Reply 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team February 2, 2021 11:53 AM UTC

Hi Nitin, 

Greetings from Syncfusion support. 

By default, Grid will map the field values of Field and ForeignKeyField value based on the DataSources provided for Grid and the GridForeignColumn and display the value of ForeignKeyValue. On analyzing your shared application, we could not find any field name as ControllerId in MasterRoleController class.  

To display the DisplayName value, the mapping should be done between the ControllerId values available in both MasterDataAdapter<MasterRolePermission> and MasterDataAdapter<MasterRoleController>. So please ensure to contain a ControllerId in both Grid and GridForeignColumn Datasources. 

And also please ensure to have equal Field and ForeignKeyField values in the DataSources of Grid and GridForeignColumn, so that the DisplayName value will get displayed. 

References :  
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer
Loader.
Up arrow icon