Error in Query Builder When Loading Rules on Load after changing example to Async

Hi,

Can you check if supporting an async data service will work while loading RuleModels?

I am implementing the example below:

All works until I try to use a service to provide data to dataSource and Datagrid that is async.

When I do this and comment out the new rule creation the example works.
When I try to create a rule for importRules ( RuleModel ) , I get the following error...


fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'hiddenYAam_eJXYNyz-HSRj4ay6uQnG05c'.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at Syncfusion.Blazor.QueryBuilder.Internal.QueryBuilderRules`1.SetField()
         at Syncfusion.Blazor.QueryBuilder.Internal.QueryBuilderRules`1.OnParametersSetAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
and....

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'X3TpRDzlxTdAyL3rMpqlG0aZXj6-ozoUZPlM3i9QELI'.
      System.ArgumentNullException: Value cannot be null. (Parameter 'name')
         at System.Type.GetProperty(String name, BindingFlags bindingAttr)
         at Syncfusion.Blazor.Data.DataUtil.GetKeyValue(String key, Object value)
         at Syncfusion.Blazor.Navigations.Internal.ListGeneration`1.UpdateHierarchicalAndSelfProps(IEnumerable`1 dataSource, String attributes)
         at Syncfusion.Blazor.Navigations.Internal.ListGeneration`1.IdentifyDataSource(Boolean IsUpdateChecked)
         at Syncfusion.Blazor.Navigations.SfTreeView`1.UpdateData(List`1 dataSource, Boolean IsUpdateChecked)
         at Syncfusion.Blazor.Navigations.SfTreeView`1.OnPropertyChangeHandler()
         at Syncfusion.Blazor.Navigations.SfTreeView`1.OnParametersSetAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

Here are the lines changed:

                                <SfQueryBuilder @ref="querybuilder" TValue="hiddenSKUs" DataSource="@dataSource">
                                    <QueryBuilderRule Condition="and" Rules="@importRules" ></QueryBuilderRule>
                                    <QueryBuilderEvents TValue="VMembership_SKUs" Created="created" RuleChanged="updateRule"></QueryBuilderEvents>


And...

    protected override async Task OnInitializedAsync()
    {...
And...

            dataSource = await hidden_SKUsService.hidden_SKUsList();
            gridData = await hidden_SKUsService.hidden_SKUsList();

And...
    private async void updateRule(Syncfusion.Blazor.QueryBuilder.RuleChangeEventArgs args)
    {...

if Rules.Count>0
gridData = querybuilder.GetFilteredRecords().ToList().AsEnumerable<hidden_SKUs>();

else
gridData = await hidden_SKUsService.hidden_SKUsList();


Once again, with all the changes... When I comment out the creation of the RuleModel, the example works but I have to put a condition in manually each time it loads.


Please let me know what I am missing.


3 Replies

AS Aravinthan Seetharaman Syncfusion Team June 5, 2021 02:20 AM UTC

Hi Victor, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked your query in our latest version 19.1.0.66. We cannot reproduce your reported issue in our end. For your refence we have prepared code snippet and sample here. 
 
 
<div class="col-lg-12 control-section"> 
    <p>Condition: @condition</p> 
    <SfQueryBuilder @ref="Querybuilder" TValue="HardWareDetails" DataSource="@DataSource" MatchCase="false"> 
        <QueryBuilderRule Condition="or" Rules="@ImportRules"></QueryBuilderRule> 
        <QueryBuilderEvents TValue="HardWareDetails" Created="Created" RuleChanged="UpdateRule" OnValueChange="ValueChange"></QueryBuilderEvents> 
        <QueryBuilderColumns> 
            <QueryBuilderColumn Field="TaskID" Label="Task ID" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.Number></QueryBuilderColumn> 
            <QueryBuilderColumn Field="Name" Label="Name" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="Category" Label="Category" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="SerialNo" Label="Serial No" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="InvoiceNo" Label="Invoice No" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="Status" Label="Status" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
        </QueryBuilderColumns> 
    </SfQueryBuilder> 
</div> 
<div class="col-lg-12 control-section"> 
    <div class="content-wrapper"> 
        <div class="row"> 
            <SfGrid TValue="HardWareDetails" DataSource="@GridData" AllowPaging="true"> 
                <GridEvents Created="Created" TValue="HardWareDetails"></GridEvents> 
                <GridColumns> 
                    <GridColumn Field=@nameof(HardWareDetails.TaskID) HeaderText="TaskID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
                    <GridColumn Field=@nameof(HardWareDetails.Name) HeaderText="Name" Width="150"></GridColumn> 
                    <GridColumn Field=@nameof(HardWareDetails.Category) HeaderText="Category" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
                    <GridColumn Field=@nameof(HardWareDetails.SerialNo) HeaderText="Serial No" Width="150"></GridColumn> 
                    <GridColumn Field=@nameof(HardWareDetails.InvoiceNo) HeaderText="Invoice No" Width="150"></GridColumn> 
                    <GridColumn Field=@nameof(HardWareDetails.Status) HeaderText="Status" Width="150"></GridColumn> 
                </GridColumns> 
            </SfGrid> 
        </div> 
    </div> 
</div> 
@code{ 
    private string condition; 
    SfQueryBuilder<HardWareDetails> Querybuilder; 
    public IEnumerable<HardWareDetails> GridData { get; set; } 
    public IEnumerable<HardWareDetails> DataSource { get; set; } 
    protected override async Task OnInitializedAsync() 
    { 
        DataSource = await HardWareDetails.GetAllRecords(); 
    } 
    private async void Created() 
    { 
        GridData = Querybuilder.GetFilteredRecords().ToList().AsEnumerable<HardWareDetails>(); 
        condition = Querybuilder.Rule.Condition; 
    } 
    public List<RuleModel> ImportRules = new List<RuleModel>() 
{ 
        new RuleModel { Field = "Category", Label = "Category", Value = "Laptop", Operator = "equal", Type = "String" } 
    }; 
    private async void UpdateRule(Syncfusion.Blazor.QueryBuilder.RuleChangeEventArgs args) 
    { 
        if (args.Rule.Rules.Count > 0) 
        { 
            GridData = Querybuilder.GetFilteredRecords().ToList().AsEnumerable<HardWareDetails>(); 
        } 
        else 
        { 
            GridData = Querybuilder.GetFilteredRecords().ToList().AsEnumerable<HardWareDetails>(); 
        } 
 
        RuleModel rule = Querybuilder.GetValidRules(); 
        condition = rule.Condition; 
        //StateHasChanged(); 
    } 
    private void ValueChange(Syncfusion.Blazor.QueryBuilder.ChangeEventArgs args) 
    { 
        GridData = Querybuilder.GetFilteredRecords().ToList().AsEnumerable<HardWareDetails>(); 
        RuleModel rule = Querybuilder.GetValidRules(); 
        condition = rule.Condition; 
        StateHasChanged(); 
    } 
} 
 
  
 
If you are still facing the issue, kindly share the below details. 
 
·        If possible, try to reproduce the reported issue in provided sample or share the issue reproducible sample. 
·        Please share us the video demonstration of this issue. 
·        Please share us the Syncfusion Package Version. 
 
Please provide the above requested information, based on that we will check and provide you a better solution quickly. 
 
Regards, 
Aravinthan S 



JO Joseph Omas December 1, 2022 03:06 PM UTC

Hi everyone, any update on this? I got the same error.



YA YuvanShankar Arunagiri Syncfusion Team December 5, 2022 11:22 AM UTC

Hi Joseph,

 

As we mentioned earlier, we are unable to replicate this issue on our end. For your reference, we have prepared the sample based on the previous update.



If you are still facing the issue, please share the below details.

  • Share a reproducible sample or replicate the issue in our sample.

  • Share the issue's video demonstration.

Based on that, we will check and provide you with a better solution quickly.

 

Regards,

YuvanShankar A


Attachment: BlazorApp20_17657df0.zip

Loader.
Up arrow icon