TreeGrid works fine with DataSource and local list, however when using SfDataManager there is an unhandled null reference error.

Full error within chome dev tools using SfDataManager:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: Object reference not set to an instance of an object.

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

   at Syncfusion.Blazor.TreeGrid.SfTreeGrid`1[[ Project .Shared.Models.Group, Project.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ConvertToFlatData(DataReadyArgs`1 dm)

   at Syncfusion.Blazor.TreeGrid.SfTreeGrid`1[[ Project .Shared.Models.Group, Project .Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetFlatData(IEnumerable dataSource, DataReadyArgs`1 dm, Boolean isRemoteChild, Boolean isGanttRecord)

   at Syncfusion.Blazor.TreeGrid.Internal.GridRenderer`1[[ Project .Shared.Models.Group, Project .Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GridDataBound(Object data)

   at Syncfusion.Blazor.Grids.Internal.EventAggregator.<>c__DisplayClass2_0.<Notify>b__0(Action`1 handler)

   at System.Collections.Generic.List`1[[System.Action`1[[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForEach(Action`1 action)

   at Syncfusion.Blazor.Grids.Internal.EventAggregator.Notify(String name, Object args)

   at Syncfusion.Blazor.Grids.SfGrid`1.<VirtualDataProcess>d__412[[System.Dynamic.ExpandoObject, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()

   at Syncfusion.Blazor.Grids.SfGrid`1.<DataProcessChild>d__410[[System.Dynamic.ExpandoObject, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()

   at Syncfusion.Blazor.Grids.SfGrid`1.<DataProcess>d__409[[System.Dynamic.ExpandoObject, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()

   at Syncfusion.Blazor.Grids.SfGrid`1.<DataProcess>d__409[[System.Dynamic.ExpandoObject, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()

   at Syncfusion.Blazor.Grids.Internal.Preloader`1.<OnParametersSetAsync>d__21[[System.Dynamic.ExpandoObject, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)


TreeGrid component with SfDataManager that errors

<SfTreeGrid @ref="GroupTreeGrid" TValue="Group" Query="@GroupsQuery" Toolbar="@(new List<string>() { "Search", "Add", "Delete" })" AllowRowDragAndDrop="true" Height="auto" IdMapping="GroupID" ParentIdMapping="ParentGroupID" TreeColumnIndex="1">
                <SfDataManager @ref="GroupsAdaptor" Url="api/groups" CrossDomain="true" Adaptor="Syncfusion.Blazor.Adaptors.WebApiAdaptor"></SfDataManager>
                <TreeGridEvents QueryCellInfo="QueryCellInfoHandler" RowSelected="RowSelectHandler" RowDeselected="RowDeSelectHandler" TValue="Group"></TreeGridEvents>
                <TreeGridPageSettings PageSize="2"></TreeGridPageSettings>
                <TreeGridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></TreeGridSelectionSettings>
                <TreeGridEditSettings AllowAdding="true" AllowDeleting="true" Mode="EditMode.Dialog">
                <Template>
                    @{
                        var Group = (context as Group);
                        <div>
                            <div class="form-row">
                            <div class="form-group col-md-12">
                                <SfTextBox ID="GroupID" @bind-Value="@Group.GroupID" FloatLabelType="FloatLabelType.Always" Placeholder="Group ID"></SfTextBox>
                            </div>
                            <div class="form-group col-md-12">
                                <SfTextBox ID="Name" @bind-Value="@Group.Name" FloatLabelType="FloatLabelType.Always" Placeholder="Name"></SfTextBox>
                            </div>
                            <div class="form-group col-md-12">
                                <SfTextBox ID="ImageURL" @bind-Value="@Group.ImageURL" FloatLabelType="FloatLabelType.Always" Placeholder="Image"></SfTextBox>
                            </div>
                            <div class="form-group col-md-12">
                                <SfTextBox ID="Description" Multiline="true" @bind-Value="@Group.Description" FloatLabelType="FloatLabelType.Always" Placeholder="Description"></SfTextBox>
                            </div>
                            </div>
                        </div>
                    }
                </Template>
                </TreeGridEditSettings>
                <TreeGridColumns>
                    <TreeGridColumn Field="GroupID" IsPrimaryKey="true" HeaderText="Group ID" Visible="false"></TreeGridColumn>
                    <TreeGridColumn Field="Name" HeaderText="Group Name"></TreeGridColumn>
                </TreeGridColumns>
            </SfTreeGrid>

TreeGrid component with Datasource that works

<SfTreeGrid DataSource="GroupsList" @ref="GroupTreeGrid" TValue="Group" Query="@GroupsQuery" Toolbar="@(new List<string>() { "Search", "Add", "Delete" })" AllowRowDragAndDrop="true" Height="auto" IdMapping="GroupID" ParentIdMapping="ParentGroupID" TreeColumnIndex="1">
                <TreeGridEvents QueryCellInfo="QueryCellInfoHandler" RowSelected="RowSelectHandler" RowDeselected="RowDeSelectHandler" TValue="Group"></TreeGridEvents>
                <TreeGridPageSettings PageSize="2"></TreeGridPageSettings>
                <TreeGridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></TreeGridSelectionSettings>
                <TreeGridEditSettings AllowAdding="true" AllowDeleting="true" Mode="EditMode.Dialog">
                <Template>
                    @{
                        var Group = (context as Group);
                        <div>
                            <div class="form-row">
                            <div class="form-group col-md-12">
                                <SfTextBox ID="GroupID" @bind-Value="@Group.GroupID" FloatLabelType="FloatLabelType.Always" Placeholder="Group ID"></SfTextBox>
                            </div>
                            <div class="form-group col-md-12">
                                <SfTextBox ID="Name" @bind-Value="@Group.Name" FloatLabelType="FloatLabelType.Always" Placeholder="Name"></SfTextBox>
                            </div>
                            <div class="form-group col-md-12">
                                <SfTextBox ID="CaddieImageG" @bind-Value="@Group.ImageURL" FloatLabelType="FloatLabelType.Always" Placeholder="Image"></SfTextBox>
                            </div>
                            <div class="form-group col-md-12">
                                <SfTextBox ID="Description" Multiline="true" @bind-Value="@Group.Description" FloatLabelType="FloatLabelType.Always" Placeholder="Description"></SfTextBox>
                            </div>


                            </div>
                        </div>
                    }
                </Template>
                </TreeGridEditSettings>
                <TreeGridColumns>
                    <TreeGridColumn Field="GroupID" IsPrimaryKey="true" HeaderText="Group ID" Visible="false"></TreeGridColumn>
                    <TreeGridColumn Field="Name" HeaderText="Group Name"></TreeGridColumn>
                </TreeGridColumns>
            </SfTreeGrid>

Code definitions

    public List<Group> GroupsList = new List<Group>();
    SfTreeGrid<Group>? GroupTreeGrid = null;
    SfDataManager? GroupsAdaptor = null;
    Query? GroupsQuery { get; set; } = null;
    Group? SelectedData = new Group();

    public partial class Group

    {

        [Key]
        public int ID { get; set; }
        public string? GroupID { get; set; }
        public string? ParentGroupID { get; set; }
        public string? Name { get; set; }
        public string? ShopID { get; set; }
        public bool Archived { get; set; }
        public bool ShowInApp { get; set; }
        public string? ImageURL { get; set; }
        public string? Description { get; set; }
    }

Controller API Get

        public async Task<ActionResult> Get(string shopid, string? search = null, string orderby = "Name", bool all = false, bool count = false)
        {
            try
            {
                if (Request.Query.Keys.Contains("$orderby"))
                {
                    orderby = Request.Query["$orderby"];
                }


                IQueryable<Group> groups = from u in context.Groups where u.ShopID == shopid select u;


                if (!all)
                {
                    groups = from p in groups where p.Archived == false select p;
                }


                if (!String.IsNullOrEmpty(search))
                {
                    groups = groups.Where(c => c.Name.Contains(search) || c.Description.Contains(search));
                }


                if (!string.IsNullOrWhiteSpace(orderby))
                {
                    var sort = orderby.Split(",".ToCharArray());
                    foreach (var s in sort)
                    {
                        if (s.EndsWith(" desc"))
                        {
                            string[] parts = s.Split(" ");
                            groups = groups.OrderByDescending(parts.First());
                        }
                        else
                        {
                            groups = groups.OrderBy(s);
                        }
                    }
                }


                if (count)
                {
                    var js = new { Items = await groups.ToListAsync(), Count = await groups.CountAsync() };
                    return Ok(js);
                }
                else
                {
                    return Ok(new { Items = await groups.ToListAsync() });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Get Groups");
                return NotFound();
            }
        }

Local data on initialisation for datasource that works

    protected override void OnInitialized()
    {
        GroupsList.Add(new Group() { ID = 1, GroupID = "1", Name = "Club", ShopID = "DEMO", Archived = false, ParentGroupID = null, ShowInApp = true });
        GroupsList.Add(new Group() { ID = 2, GroupID = "2", Name = "Accessories", ShopID = "DEMO", Archived = false, ParentGroupID = "1", ShowInApp = true });
        GroupsList.Add(new Group() { ID = 3, GroupID = "3", Name = "Accessories - More", ShopID = "DEMO", Archived = false, ParentGroupID = "1", ShowInApp = true });

        GroupsQuery = new Query().AddParams("shopid", shop.id).AddParams("search", null).AddParams("orderby", "Name").AddParams("all", false).AddParams("count", false);
    }

What is this error referring to?


1 Reply

PS Pon Selva Jeganathan Syncfusion Team October 26, 2021 04:12 PM UTC

Hi Jordan,   
 
Thanks for contacting syncfusion forum. 
 
Query: TreeGrid works fine with DataSource and local list, however when using SfDataManager there is an unhandled null reference error. 

We checked your query by preparing sample (Using sfDatamanager), but we were unable to reproduce the issue(Script error thrown while using SfDataManager) at our end.  
 
Please refer to the below sample, 
 

After following the above reference, still faced issue please share us the following details.

  1. If possible, reproduce the issue in the attached sample or share the issue reproducible sample.
  2. Share the product detail version.
  3. Share the video demo or screenshot of the issue
  4. Share the network tab details.
 
The provided information will be helpful to provide you response as early as possible.   

Regards,  
Pon selva   
 


Loader.
Up arrow icon