- Home
- Forum
- ASP.NET Core - EJ 2
- When using IN operator, Value does not populate correctly in Query builder
When using IN operator, Value does not populate correctly in Query builder
I am trying to populate data from the controller into the builder. I can get it working with the equal and greaterthan operators. However, when I try to use the in operator. The value is not rendering correctly and is causing a console error. The value is the string "JEWEL" and when I see it in the query builder it shows ,J,E,W,E,L. This is causing a console error. I need it to render the entire string as a single string.
QueryBuilderRule rule = new QueryBuilderRule { Label = splitString[0], Field = splitString[0], Type = "string", Operator = "in", Value = "JEWEL" });
QueryBuilderRule query = new QueryBuilderRule()
{
Condition = condition,
Rules = rule
};
ViewBag.rule = query;
<ejs-querybuilder id="querybuilder" width="73%" rule="ViewBag.rule" columns="ViewBag.Columns" maxGroupCount=5 created="createdControl">
</ejs-querybuilder>
Thanks,
Dana
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
GK
Gayathri KarunaiAnandam
Syncfusion Team
March 11, 2021 04:22 PM UTC
Hi Dana,
Thank you for contacting Syncfusion support.
We have checked your reported query. We would like to let you know that “in” operator is used to select multiple items. So, we render a multiselect component. In your code snippet, you have used a single string as value. So, it split the value into multiple items. For in operator, you have to pass the value in an array. Please check the below code snippet and sample
HomeController.cs
|
List<string> values = new List<string> { "Sales Manager" };
QueryBuilderRule rule = new QueryBuilderRule()
{
Condition = "and",
Rules = new List<QueryBuilderRule>()
{
new QueryBuilderRule { Label="Employee ID", Field="EmployeeID", Type="number", Operator="equal", Value = 1 },
new QueryBuilderRule { Label="Title", Field="Title", Type="string", Operator="in", Value = values }
}
};
ViewBag.rule = rule;
ViewBag.dataSource = EmployeeView.GetAllRecords();
return View(); |
Please get back to us, if you need further assistance.
Regards,
Gayathri K
DK
Dana Kiehl
March 11, 2021 09:12 PM UTC
Hello,
Thanks for the response. It partially solved the issue I was having. I can now get the array of items to populate in the box but only if I don't have a datasource. If I have a datasource the values don't populate and there is a multiselect dropdown to choose items from. If I take the datasource out, the values will populate upon rendering but there is obviously no multiselect dropdown.
Thanks,
Dana
GK
Gayathri KarunaiAnandam
Syncfusion Team
March 12, 2021 11:35 AM UTC
Hi Dana,
We have checked your reported query. We would like to let you know that for in operator our behavior is when there is datasource we will render multiselect component. If there is no datasource, we will render textbox component. We have prepared a sample in which textbox will render. Please check the below code snippet and sample.
Index.cshtml
|
<ejs-querybuilder id="querybuilder" width="73%" rule="ViewBag.rule" >
<e-querybuilder-columns>
<e-querybuilder-column field="EmployeeID" label="Employee ID" type="number"></e-querybuilder-column>
<e-querybuilder-column field="FirstName" label="First Name" type="string"></e-querybuilder-column>
<e-querybuilder-column field="TitleOfCourtesy" label="Title Of Courtesy" type="boolean" values="ViewBag.values"></e-querybuilder-column>
<e-querybuilder-column field="Title" label="Title" type="string"></e-querybuilder-column>
<e-querybuilder-column field="HireDate" label="Hire Date" type="date" format="dd/MM/yyyy"></e-querybuilder-column>
<e-querybuilder-column field="Country" label="Country" type="string"></e-querybuilder-column>
<e-querybuilder-column field="City" label="City" type="string"></e-querybuilder-column>
</e-querybuilder-columns>
</ejs-querybuilder> |
HomeController.cs
|
public ActionResult Index()
{
List<string> values = new List<string> { "Sales Manager" };
QueryBuilderRule rule = new QueryBuilderRule()
{
Condition = "and",
Rules = new List<QueryBuilderRule>()
{
new QueryBuilderRule { Label="Employee ID", Field="EmployeeID", Type="number", Operator="equal", Value = 1 },
new QueryBuilderRule { Label="Title", Field="Title", Type="string", Operator="in", Value = values }
}
};
ViewBag.rule = rule;
return View();
} |
Please get back to us, if you need further assistance.
Regards,
Gayathri K
Marked as answer
DK
Dana Kiehl
March 16, 2021 02:03 PM UTC
Thank you for your help on this, I was able to get this working on my project.
GK
Gayathri KarunaiAnandam
Syncfusion Team
March 17, 2021 04:47 AM UTC
Hi Dana,
Thanks for the update.
We are happy to hear that your requirement has been fulfilled. Please feel free to contact us if you need any further assistance on this.
Regards,
Gayathri K
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
- Marked answer
-
DK Dana Kiehl
- Mar 10, 2021 10:19 PM UTC
- Mar 17, 2021 04:47 AM UTC