Is there a way to add code behind method for Load On Demand

Hi,

We have a lot of data to be shown in Tree Grid.
We wold like to show all nodes collapsed on load of page and than to Load on demand child nodes when expanding parent.
Is there a way to add code behind method for Load On Demand?

Best regards,

Igor Surla

7 Replies 1 reply marked as answer

GL Gowri Loganathan Syncfusion Team August 13, 2020 12:22 PM UTC

 
Hi Igor Surla, 

Thanks for contacting Syncfusion Forum. 

Query: We would like to show all nodes collapsed on load of page and then to Load on demand child nodes when expanding parent. 

The Tree Grid provides Load on Demand support for binding large data. To bind large data to Tree Grid component, we suggest you to use remote service and assign service link to Url property of SfDataManager. In the below demo sample we have used WebApiAdaptor to the SfDataManager to consume WebApi service. 
 
Note : When load on demand is enabled, all the root nodes are rendered in collapsed state at initial load. 

Code 
@using Syncfusion.Blazor.Grids; 
@using Syncfusion.Blazor.TreeGrid; 
@using Syncfusion.Blazor.Data; 

<SfTreeGrid IdMapping="TaskID" ParentIdMapping="ParentItem" HasChildMapping="isParent" AllowPaging="true" TreeColumnIndex="1"> 
<SfDataManager Url="https://ej2services.syncfusion.com/production/web-services/api/SelfReferenceData" CrossDomain="true" Adaptor="Syncfusion.Blazor.Adaptors.WebApiAdaptor"></SfDataManager> 
<TreeGridColumns> 
………………….. . 
</TreeGridColumns> 
</SfTreeGrid> 

@code{ 
……………….. 

} 
 
Output 
 

Refer to the below demo link, 

Also, refer to the below help documentation link. 

Kindly get back to us if you need more assistance. We will be happy to assist you. 

Regards, 
Gowri V L 




IS Igor Surla August 13, 2020 12:58 PM UTC

Hi Gowri,

We are using ExpandoObject to dynamically create data source and columns.
We would like to have our own Load On Demand mechanism.

You have not answered my question:
Is there a way to add our own logic for Load On Demand for example a method which will retrieve data?

Best regards,
Igor Surla


GL Gowri Loganathan Syncfusion Team August 14, 2020 02:49 PM UTC

Hi Igor Surla, 
 
Thanks for the update. 
 
Query: Is there a way to add our own logic for Load On Demand for example a method which will retrieve data? 
 
To achieve your requirement, we suggest you to use our custom data binding feature of Tree Grid. For that we have Custom Adaptor support in SfDataManager which is used to implement the custom data binding in Tree Grid. The DataAdaptor class is used as an abstract class for custom data binding in which it act as a base class for the custom Adaptor. The custom data binding can be implemented in the Tree Grid component by providing the CustomAdaptor class and overriding the Read or ReadAsync method of the DataAdaptor abstract class as shown below. 
 
Code  
<SfTreeGrid TValue="SelfReferenceData" HasChildMapping="isParent" IdMapping="TaskID" ParentIdMapping="ParentID" TreeColumnIndex="1">   <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
    <TreeGridColumns> 
……………..  . 
    </TreeGridColumns> 
</SfTreeGrid> 
@code{ 
     
    // Implementing custom adaptor by extending the DataAdaptor class 
 
    public class CustomAdaptor : DataAdaptor 
    { 
    // Performs data Read operation 
    public override object Read(DataManagerRequest dm, string key = null) 
    { 
    …………………….. .  
    } 
    } 
 
Kindly refer the below documentation link for more information on Custom binding, 
 
Please revert us if you need further assistance. 
 
Regards, 
Gowri V L  
 
 



BA Basil Aishi August 14, 2020 03:40 PM UTC

Hi Gowri,

thanks for your reply.
if you note Igor's point, he is using a  List<ExpandoObject > as the source.

Code would look like this:
<SfTreeGrid TValue="ExpandoObject" IdMapping="Id"
            ParentIdMapping="ParentId" Columns="@TreeColumns"
            TreeColumnIndex="0" AllowSorting="true" AllowPaging="true" HasChildMapping="HasChildMapping">
    <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor">
        
    </SfDataManager>
</SfTreeGrid>

please note that TValue is ExpandoObject. 
now when we return in the Adaptor the below: return dataManagerRequest.RequiresCounts ? new DataResult() { Result = results, Count = results.Count } : (object)results;
we notice that the TreeGrid displays the counts but does not display any data.

Is ExpandoObject as a TValue not supported? and if it is, what is wrong here?

thanks


GL Gowri Loganathan Syncfusion Team August 17, 2020 01:56 PM UTC

  
  
Hi Basil, 

Thanks for the update. 

We are able to reproduce the reported issue when using custom adaptor with expandoObj. We have considered this as a bug and we have logged the bug report for the this. So fix for the same will be included in our Nuget release after the Volume 2 Service Pack 1 release which is expected to be rolled out in the end of August 2020. 

You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.    

Note: To view the above feedback, kindly login into your account.   
 
Until then we appreciate your patience. 

Regards, 
Gowri V L 
 


Marked as answer

BA Basil Aishi August 17, 2020 01:57 PM UTC

Today, I upgraded from  18.2.0.46 to 18.2.0.48, and the TreeGrid started failing with the following error:
System.InvalidOperationException: The converter specified on 'Syncfusion.Blazor.TreeGrid.TreeGridColumn.EditTemplate' does not derive from JsonConverter or have a public parameterless constructor.

After some investigation, I ended up removing the binding from Columns="" and replacing it with a foreach like below:
    <TreeGridColumns>
        @foreach (var treeGridColumn in @TreeColumns)
        {
            <TreeGridColumn Field="@treeGridColumn.Field" HeaderText="@treeGridColumn.HeaderText" Width="@treeGridColumn.Width"></TreeGridColumn>
        }
    </TreeGridColumns>

which ended up fixing my problem and now the TreeGrid shows the columns and I don't get the above error.

However, after the data is populated I see it flashing in the UI and then immediately disapears.
Again, I am still using a Custom Adaptor like below:
    <SfDataManager CrossDomain="true" AdaptorInstance="@typeof(CustomAdaptor)"
                   Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor" Offline="true">

    </SfDataManager>

so my problem now is that the data when loaded flashes for a quick millisecond on the UI, and then disappears leaving the TreeGrid with the message "No Records to Display".

Can you please let me know what needs to change?

This is my Adaptor Read:
public override object Read(DataManagerRequest dm, string key = null)
        {
            var results = new List<ExpandoObject>(CustomService.TreeGridRows);
            IEnumerable<ExpandoObject> dataSource = results;
            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);
            //}
            var count = dataSource.Cast<ExpandoObject>().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;
        }


and here is the TreeGrid razor code:

<SfTreeGrid @ref="TreeGrid" TValue="ExpandoObject" IdMapping="Id"
            ParentIdMapping="ParentId"
            TreeColumnIndex="0" AllowPaging="true" EditSettings="@EditSettings">

    <SfDataManager CrossDomain="true" AdaptorInstance="@typeof(CustomAdaptor)"
                   Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor" Offline="true">

    </SfDataManager>

    <TreeGridPageSettings PageCount="2" PageSize="20" PageSizeMode="PageSizeMode.All"></TreeGridPageSettings>
    <TreeGridColumns>
        @foreach (var treeGridColumn in @TreeColumns)
        {
            <TreeGridColumn Field="@treeGridColumn.Field" HeaderText="@treeGridColumn.HeaderText" Width="@treeGridColumn.Width"></TreeGridColumn>
        }
    </TreeGridColumns>
</SfTreeGrid>


BA Basil Aishi August 17, 2020 02:01 PM UTC

Hi Gowri,

thanks for the update. our messages probably went through at the same time. looking forward for the fix, and also please note of the other issue I mentioned in my last message and the workaround that we had to make.

For the link that you provided I get access denied, is there another way to track it?

thanks,
Basil

Loader.
Up arrow icon