Repository navigation
Expand file tree
/
Copy pathcustom-value.js
More file actions
44 lines (43 loc) · 2.18 KB
/
Copy pathcustom-value.js
File metadata and controls
44 lines (43 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
this.default = function () {
// initialize ComboBox component
var comboBoxObj = new ej.dropdowns.ComboBox({
// set the local data to dataSource property
dataSource: window.ddCountryData,
// map the appropriate columns to fields property
fields: { text: 'Name', value: 'Code' },
// set the placeholder to ComboBox input element
placeholder: 'Select a country',
// set the height of the popup element
popupHeight: '300px',
// set true for enable the filtering support
allowFiltering: true,
// bind the filtering event
filtering: function (e) {
var query = new ej.data.Query();
// frame the query based on search string with filter type.
query = (e.text !== '') ? query.where('Name', 'startswith', e.text, true) : query;
// pass the filter data source, filter query to updateData method.
e.updateData(window.ddCountryData, query);
if (document.getElementById('nodata')) {
// bind click event to button element
document.getElementById('btn').onclick = function () {
// get the typed characters
var customValue = document.getElementById('country').value;
// make new object based on typed characters
var newItem = { 'Name': customValue, 'Code': customValue };
// new object added to data source.
comboBoxObj.dataSource.push(newItem);
// close the popup element.
comboBoxObj.hidePopup();
// pass new object to addItem method.
comboBoxObj.addItem(newItem);
// select the newly added item.
comboBoxObj.value = customValue;
};
}
},
// set the template content when the typed character(s) is not present in the list
noRecordsTemplate: '<div><div id="nodata"> No matched item, do you want to add it as new item in list?</div><button id="btn" class="e-control e-btn">Add New Item</button></div>',
});
comboBoxObj.appendTo('#country');
};