Datamanager query not working as expected

Hi,

I was trying to make an implementation using a DataManager and a Query, I couldn't make it work. I always get the first 5 items despite chaning the query to return all the items.

I trying adding "StateHasChanged();" and/or "TreeViewRef.Refresh();", which changes anything. 

What am I doing wrong? 

This is the content of [Index.razor], updated from the provided: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp11352758965.zip


@page "/"


@using Syncfusion.Blazor.Navigations

@using Syncfusion.Blazor.Data


<SfTreeView TValue="MailItem" @ref="TreeViewRef">

    <TreeViewFieldsSettings TValue="MailItem" Id="Id"

        Text="FolderName" ParentID="ParentId"

        HasChildren="HasSubFolders" Expanded="Expanded"

        Query="@DataQuery">

        <SfDataManager @ref="DataManagerRef"

                       AdaptorInstance="@typeof(CustomAdaptor)"

                       Adaptor="Adaptors.CustomAdaptor">

        </SfDataManager>

    </TreeViewFieldsSettings>

    @*DataSource="@MyItems"*@

</SfTreeView>


<span @onclick="ExpandCollapse">@ExpandCollapseText</span>


@code{


    public class MailItem

    {

        public string? Id { get; set; }

        public string? ParentId { get; set; }

        public string? FolderName { get; set; }

        public bool Expanded { get; set; }

        public bool HasSubFolders { get; set; }

    }


    public SfDataManager DataManagerRef { get; set; }

    public SfTreeView<MailItem> TreeViewRef { get; set; }

    public Query DataQuery;


    private static List<MailItem> MyItems = new List<MailItem>();

    private string? ExpandCollapseText;

    private bool isExpanded;


    protected override async Task OnInitializedAsync()

    {

        base.OnInitialized();

        MyItems = GetItemsFromSomeWhere(); // e.g. get all the items from a web service or whatever

        isExpanded = false;

        //DataQuery = new Query().Take(3);

        await ExpandCollapse();

    }


    public async Task ExpandCollapse()

    {

        if (isExpanded)

        {

            DataQuery = new Query().Take(MyItems?.Count ?? 0);

            ExpandCollapseText = "Show less";

        }

        else

        {

            DataQuery = new Query().Take(5);

            ExpandCollapseText = $"See all {MyItems?.Count} items";

        }


        isExpanded = !isExpanded;

        if (DataManagerRef != null)

            await DataManagerRef?.ExecuteQueryAsync<MailItem>(DataQuery);


        //if (TreeViewRef != null)

        // TreeViewRef.Refresh();

        //StateHasChanged();

    }


    public class CustomAdaptor : DataAdaptor

    {

        // Performs data Read operation

        public override object Read(DataManagerRequest dm, string key = null)

        {

            IEnumerable<MailItem> DataSource = MyItems; // ?? new List<MailItem>();

            int count = DataSource.Cast<MailItem>().Count();

            DataSource = DataOperations.Execute<MailItem>(DataSource, dm);

            if (dm.RequiresCounts)

                return new DataResult() { Result = DataSource, Count = count };

            else

                return (object)DataSource;

        }

    }


    private List<MailItem> GetItemsFromSomeWhere()

    {

        var items = new List<MailItem>();

        items.Add(new MailItem

            {

                Id = "1",

                FolderName = "Inbox",

            });

        items.Add(new MailItem

            {

                Id = "2",

                FolderName = "Categories",

            });

        items.Add(new MailItem

            {

                Id = "3",

                FolderName = "Primary"

            });

        items.Add(new MailItem

            {

                Id = "4",

                FolderName = "Social"

            });

        items.Add(new MailItem

            {

                Id = "5",

                FolderName = "Promotions"

            });

        items.Add(new MailItem

            {

                Id = "6",

                FolderName = "Additional details_01",

            });

        items.Add(new MailItem

            {

                Id = "7",

                FolderName = "Additonal details_02",

            });

        items.Add(new MailItem

            {

                Id = "8",

                FolderName = "Additional details_03"

            });

        items.Add(new MailItem

            {

                Id = "9",

                FolderName = "Additional details_04"

            });

        items.Add(new MailItem

            {

                Id = "10",

                FolderName = "Additional details_05"

            });

        items.Add(new MailItem

            {

                Id = "11",

                FolderName = "Additional details_06"

            });

        return items;

    }


}



Thanks


3 Replies

SS Sivakumar ShunmugaSundaram Syncfusion Team September 8, 2022 03:22 PM UTC

Hi horacioj,


We have validated the reported issue in the TreeView component and considered it as a bug at our end. The fix for this issue will be included in our weekly patch release on October 04, 2022. You can track the status of the issue fix using the following feedback link.


Feedback link: https://www.syncfusion.com/feedback/37633/while-dynamically-binding-custom-adaptor-data-using-query-property-will-not-update


Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.


We appreciate your patience.


Regards,

Sivakumar S



HO horacioj September 8, 2022 03:23 PM UTC

Thanks!



SS Sivakumar ShunmugaSundaram Syncfusion Team October 7, 2022 07:59 AM UTC

Hi horacioj,


We are glad to announce that our patch release (V20.3.48) has been rolled out successfully. The issue with “Dynamically binding custom adaptor data using query property will not update the node count in Treeview” has been resolved in this release. To access this fix, we suggest you update the package to 20.3.48.


Samplehttps://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp1125579816.zip


Feedback: https://www.syncfusion.com/feedback/37633/dynamically-binding-custom-adaptor-data-using-query-property-will-not-update-the


Release Notes: https://blazor.syncfusion.com/documentation/release-notes/20.3.48?type=all#treeview


Please let us know if you need any further assistance.


Regards,

Sivakumar S


Loader.
Up arrow icon