Populating the in and not in dropdown in querybuilder without using data binding

Is it possible to populate the "In" and "Not In" operator dropdown without using the data binding feature of the querybuilder?

What I'd like to do is only get and populate a "In/Not In" operator dropdown when the operator is selected for a field and only for that field.



12 Replies

AS Aravinthan Seetharaman Syncfusion Team December 7, 2020 05:06 PM UTC

Hi Michael Aston, 
  
Thanks for contacting Syncfusion support. 
We have checked your reported issue, and we can able to bind operators for particular field without using data binding options. 
@using Syncfusion.Blazor.QueryBuilder 
 
<SfQueryBuilder TValue="EmployeeDetails"> 
    <QueryBuilderColumns> 
        <QueryBuilderColumn Field="EmployeeID" Label="Employee ID" Type="ColumnType.Number" Operators="@operators"></QueryBuilderColumn> 
    </QueryBuilderColumns> 
</SfQueryBuilder> 
 
@code {  
    private List<OperatorsModel> operators = new List<OperatorsModel> { 
        new OperatorsModel { Text="In",Value="in"}, 
        new OperatorsModel{Text="NotIn",Value="notin"} 
    }; 
    public class EmployeeDetails{ 
        public int EmployeeID { get; set; } 
    }  
 } 
  
Based on your requirement, we have prepared sample here: 
Could you please check with above details, and get back to us if you need any further assistance on this. 
  
Regards, 
Aravinthan S. 



MA Michael Aston December 7, 2020 09:39 PM UTC

This is not quite what I'm after. I'm not looking to restrict the available operators but rather I'm looking to hook into the population of the dropdowns that support the "In" and "Not In" operators.

I want to avoid using the databind feature of the querybuilder to populate the dropdowns as I have many columns and its takes a long to retrieve all the data to bind. Rather I'd like to just get the list for the "In" or "Not In" operator  dropdown when the column is selected in the querybuilder component. 





AS Aravinthan Seetharaman Syncfusion Team December 8, 2020 05:11 PM UTC

Hi Michael Aston, 
  
Sorry for the inconvenience caused, we have checked your requirement and we can able to achieve it by using QueryBuilderTemplate tag attribute. In the template we can define and use our required component. In the below sample we have rendered DropdownList for in and notin operator, and local data has been used for listing the items, and you can use remote data also. 
code snippet: 
    <QueryBuilderTemplates> 
                <ValueTemplate> 
                    @if (context.Operator == "notin" || context.Operator == "in") 
                    { 
                        <SfDropDownList TValue="string" TItem="ItemFields" DataSource="@Items" @bind-Value="@DefaultValue"> 
                            <DropDownListFieldSettings Text="Id"></DropDownListFieldSettings> 
                            <DropDownListEvents TItem="ItemFields" TValue="string" ValueChange="e => OnChange(e, context)"></DropDownListEvents> 
                        </SfDropDownList> 
                    } 
                    else 
                    { 
                        <SfTextBox Placeholder='Enter Value' ValueChange="e => Change(e, context)"></SfTextBox> 
                    } 
               </ValueTemplate> 
       </QueryBuilderTemplates> 
  
Could you please check with above details, and get back to us if you need any further assistance on this. 
  
Regards, 
Aravinthan S. 
  
  



MA Michael Aston December 11, 2020 01:55 PM UTC

That's great, just what I was after.

One more question, do you have a sample that shows how to use the ColumnTemplate of the QueryBuilder?


MK Mohan Kumar Ramasamy Syncfusion Team December 14, 2020 02:14 PM UTC

Hi Michael, 
 
We have checked your reported query. The Querybuilder ColumnTemplate same as ValueTemplate. 
 
Regards, 
Mohan kumar R 



MK Mohan Kumar Ramasamy Syncfusion Team December 14, 2020 02:41 PM UTC

Hi Michael, 
 
Please ignore previous update. 
 
We have prepared a sample for ColumnTemplate, please refer below code snippets and sample link. 
 
 
Code snippets 
 
 
<SfQueryBuilder TValue="Orders" @ref="qb" DataSource="@DataSource" Width="70%"> 
        <QueryBuilderEvents TValue="Orders" Created="created" RuleChanged="change"></QueryBuilderEvents> 
        <QueryBuilderRule Condition="and" Rules="@Rules"></QueryBuilderRule> 
        <QueryBuilderColumns> 
            <QueryBuilderColumn Field="CustomerID" Label="CustomerID" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="EmployeeID" Label="EmployeeID" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.Number> 
                <QueryBuilderTemplates> 
                    <ColumnTemplate> 
                        <SfDropDownList TItem="string" TValue="string" Width="340px" DataSource="qb.Columns.Select(e => e.Field)" @bind-Value="context.Label"> 
                            <DropDownListFieldSettings Text="CustomerID"></DropDownListFieldSettings> 
                            <DropDownListEvents TItem="string" TValue="string" ValueChange="e => ChangeOperator(e, context)"></DropDownListEvents> 
                        </SfDropDownList> 
                        <div> 
                            <SfSlider TValue="int" Min="0" Max="20" Value="@DefaultSliderValue"> 
                                <SliderEvents TValue="int" OnChange="e => SliderChange(e, context)"></SliderEvents> 
                                <SliderTicksData Placement="Placement.Before" LargeStep="5" SmallStep="1" ShowSmallTicks="true"></SliderTicksData> 
                            </SfSlider> 
                        </div> 
                    </ColumnTemplate> 
                </QueryBuilderTemplates> 
            </QueryBuilderColumn> 
            <QueryBuilderColumn Field="Verified" Label="Verified" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.Boolean Values=@Values></QueryBuilderColumn> 
            <QueryBuilderColumn Field="ShipName" Label="ShipName" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="OrderDate" Label="OrderDate" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.Date Format="dd/MM/yyyy"></QueryBuilderColumn> 
            <QueryBuilderColumn Field="ShipCountry" Label="ShipCountry" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
            <QueryBuilderColumn Field="ShipAddress" Label="ShipAddress" Type=Syncfusion.Blazor.QueryBuilder.ColumnType.String></QueryBuilderColumn> 
        </QueryBuilderColumns> 
    </SfQueryBuilder> 
 
 
We have rendered ColumnTemplate for EmployeeID Field 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Mohan kumar R 



MA Michael Aston December 14, 2020 07:20 PM UTC

Thanks for the sample, unfortunately the ColumnTemplate feature does not solve my issue.

The issue I'm trying to solve is that I have some long Column labels that are being truncated in the Column dropdown. To solve this I'm trying to add PopupWidth="Auto" to the dropdown. I had hoped that the ColumnTemplate would allow me to do this, which it does, but I hadn't realised that I'd loose the operator and value fields in the process, which I need to keep.

Do you have any suggestions on how to solve the truncation of long labels in the column dropdown?


AS Aravinthan Seetharaman Syncfusion Team December 15, 2020 02:39 PM UTC

Hi Michael Aston, 
  
We have checked your reported query, and we can able to achieve your requirement that to avoid truncating of labels, by using PopupWidth=”Auto”  Property in the SfDropDownList tag. 
<QueryBuilderTemplates> 
                <ValueTemplate> 
                    <SfDropDownList TValue="string" TItem="ItemFields" DataSource="@Items" @bind-Value="@DefaultValue" PopupWidth="Auto"> 
                        <DropDownListFieldSettings Text="Id"></DropDownListFieldSettings> 
                        <DropDownListEvents TItem="ItemFields" TValue="string" ValueChange="e => OnChange(e, context)"></DropDownListEvents> 
                    </SfDropDownList> 
                </ValueTemplate> 
</QueryBuilderTemplates> 

Based on your requirement we have prepared sample here. 
Could you please check the above details, and get back to us, if you need any further assistance on this. 
  
Regards, 
Aravinthan S 
  
  



MA Michael Aston December 15, 2020 03:07 PM UTC

Thanks for that, but its the column dropdown that I need to add the popupwidth="auto" to not the value dropdown.


AS Aravinthan Seetharaman Syncfusion Team December 17, 2020 03:26 AM UTC

Hi Michael Aston, 
  
Sorry for the inconvenience caused. We have checked your reported query, and we can also, achieve your requirement in Column Template as like in the sample: 
<QueryBuilderTemplates> 
                    <ColumnTemplate> 
                        <SfDropDownList TItem="string" TValue="string" width="auto" DataSource="qb.Columns.Select(e => e.Field)" @bind-Value="context.Label"> 
                            <DropDownListFieldSettings Text="CustomerID"></DropDownListFieldSettings> 
                            <DropDownListEvents TItem="string" TValue="string" ValueChange="e => ChangeField(e, context)"></DropDownListEvents> 
                        </SfDropDownList> 
                        <SfDropDownList TItem="OperatorsModel" TValue="string" Width="200px" DataSource="Operators" @bind-Value="DefaultOperaterValue"> 
                            <DropDownListFieldSettings Text="Text" Value="Value"></DropDownListFieldSettings> 
                            <DropDownListEvents TItem="OperatorsModel" TValue="string" ValueChange="e => ChangeOperator(e, context)"></DropDownListEvents> 
                        </SfDropDownList> 
                        <div> 
                            <SfSlider TValue="int" Min="0" Max="20" Value="@DefaultSliderValue"> 
                                <SliderEvents TValue="int" OnChange="e => SliderChange(e, context)"></SliderEvents> 
                                <SliderTicksData Placement="Placement.Before" LargeStep="5" SmallStep="1" ShowSmallTicks="true"></SliderTicksData> 
                            </SfSlider> 
                        </div> 
                    </ColumnTemplate> 
                </QueryBuilderTemplates> 
 
In the sample we are using SfDropDownList for Field and Operater values and SfSlider for Value of the column. Now we can able to set PopupWidth="Auto" to Field and Operator, if required. 
Could you please check the above details and get back to us, if you need further assistance on this. 
  
Regards, 
Aravinthan S 



MA Michael Aston December 18, 2020 11:33 AM UTC

Thanks for that. I wonder if you could help me further as run into another problem now. When I assign a list of Rules to the Querybuilder via 

<QueryBuilderRule Condition="or" Rules="@ScopeRules"></QueryBuilderRule>

I get a NullReference Exception

With the following stack 

  Syncfusion.Blazor.dll!Syncfusion.Blazor.QueryBuilder.Internal.QueryBuilderRules<vx.Models.DashBoardScopeField>.SetField() Unknown
  Syncfusion.Blazor.dll!Syncfusion.Blazor.QueryBuilder.Internal.QueryBuilderRules<vx.Models.DashBoardScopeField>.OnParametersSetAsync() Unknown
  Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync() Unknown

Are you able to tell me what could be causing the exception in SetField?


AS Aravinthan Seetharaman Syncfusion Team December 21, 2020 12:55 PM UTC

Hi Michael Aston, 
  
  
We have checked your reported issue, and we suspect that this exception occurs due to not setting value for Field option while framing Rules in QueryBuilder. 
 
<QueryBuilderRule Condition="or" Rules="Rules"></QueryBuilderRule> 
 
List<RuleModel> Rules = new List<RuleModel>() 
    { 
            new RuleModel { Field="Country", Label="Country", Type="String", Operator="equal", Value = "England" }, 
            new RuleModel { Field="EmployeeID", Label="EmployeeID",  Type="Number", Operator="notequal", Value = 1001 } 
    }; 
 
 
Could you please check the above details, and get back to us, if you need further assistance on this. 
  
  
Regards, 
Aravinthan S 


Loader.
Up arrow icon