Search not working as expected
Hi!
So I have a ComboBox which returns an employee's name. In my db I have a FirstName and a LastName field. In order to show the full name
I concatenated the fields like this "EmployeeLastName" + ", " + "EmployeeFirstName" (Used Automapper for that).
So my JSON returns this field. When I enter a name in the ComboBox, it seems to only search for "startsWith" - I'm only able to search for an
employee's LastName. When I try to search for the FirstName it doesn't show/highlight the result.
After looking at the API reference I tried to use the filtering method. This is my code:
var dataManagerEMP = ej.DataManager({
url: "/Employee/GetEmployees"
});
$(function () {
$("#employee").ejComboBox({
dataSource: dataManagerEMP,
allowFiltering: true,
filtering: function (e) {
query = ej.Query().where("EmployeeFullName", "contains", e.text).select("EmployeeFullName")
e.updateData(dataManagerEMP, query);
},
fields: {
value: 'EmployeeID',
text: 'EmployeeFullName'
}
});
});
This doesn't work as expected though. Still only shows the LastName.... Do you have a suggestion how I could get this working?
Thanks in advance
Paul
SIGN IN To post a reply.
3 Replies
KR
Keerthana Rajendran
Syncfusion Team
November 23, 2017 11:52 AM UTC
Hi Paul,
Thank you for contacting Syncfusion Support.
In combo box, filtering will be done based on “startswith”. If your requirement is to display the list of items filtered based on “contains” you can store the list of combo box items in a variable and process these items based on query using executeLocal method of data manager by using the below code.
|
<script type="text/javascript">
var dataManagerEMP = ej.DataManager({
url: "/Combobox/GetEmployees"
});
var data;
$(function () {
$("#employee").ejComboBox({
dataSource: dataManagerEMP,
allowFiltering: true,
filtering: function (e) {
if (!data) data = ej.DataManager(this.listData);
query = ej.Query().where("EmployeeFullName", "contains", e.text).select("EmployeeFullName");
e.updateData(data.executeLocal(query));
}, fields: {
value: 'EmployeeID',
text: 'EmployeeFullName'
}
});
});
</script>
|
We have attached a sample for reference which can be downloaded from the below link:
Regards,
Keerthana.
PK
Paul Kocher
December 7, 2017 11:47 AM UTC
Hi Keerthana,
thanks!! Now it works as expected :)
At first thought it didn't work but then I realized case-sensitive search was enabled. So for anyone having this issue this is the query working with case-sensitive search DISABLED:
<script type="text/javascript">
var dataManagerEMP = ej.DataManager({
url: "/Combobox/GetEmployees"
});
var data;
$(function () {
$("#employee").ejComboBox({
dataSource: dataManagerEMP,
allowFiltering: true,
filtering: function (e) {
console.log(e);
if (!data) data = ej.DataManager(this.listData);
query = ej.Query().where("EmployeeFullName", "contains", e.text, true);
e.updateData(data.executeLocal(query));
console.log(query);
console.log(data.executeLocal(query));
},
fields: {
value: 'EmployeeID',
text: 'EmployeeFullName'
}
});
});
</script>
Paul
PO
Prince Oliver
Syncfusion Team
December 8, 2017 04:25 AM UTC
Hi Paul,
Most Welcome and thank you for sharing your solution with us. We are glad that your issue is resolved.
Regards,
Prince
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
PK Paul Kocher
- Nov 21, 2017 10:17 AM UTC
- Dec 8, 2017 04:25 AM UTC