|
<div id="wrapper">
<button id="btn">Click to append table</button>
</div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function (args) {
document.getElementById('btn').addEventListener('click', function () {
var table = document.createElement('table');
for (var i = 1; i < 2; i++) {
var tr = document.createElement('tr');
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var text1 = document.createElement('input');
text1.setAttribute('id', 'games');
var text2 = document.createTextNode('Text2');
td1.appendChild(text1);
td2.appendChild(text2);
tr.appendChild(td1);
tr.appendChild(td2);
table.appendChild(tr);
}
document.getElementById('wrapper').appendChild(table);
var sportsData = ['Badminton', 'Basketball', 'Cricket', 'Football', 'Golf', 'Gymnastics', 'Hockey', 'Rugby', 'Snooker', 'Tennis'];
var comboBoxObj = new ej.dropdowns.ComboBox({
// set the height of the popup element
popupHeight: '230px',
dataSource: sportsData,
// set the placeholder to ComboBox input element
placeholder: 'Select a game',
});
comboBoxObj.appendTo('#games');
});
})
</script> |
|
<div id="wrapper">
<button id="btn">Click to append table</button>
</div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function (args) {
document.getElementById('btn').addEventListener('click', function () {
var table = document.createElement('table');
for (var i = 1; i < 2; i++) {
var tr = document.createElement('tr');
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var text1 = document.createElement('input');
text1.setAttribute('id', 'games');
var text2 = document.createTextNode('Text2');
td1.appendChild(text1);
td2.appendChild(text2);
tr.appendChild(td1);
tr.appendChild(td2);
table.appendChild(tr);
}
document.getElementById('wrapper').appendChild(table);
var sportsData = [
{ Id: 'Game1', Game: 'Badminton' },
{ Id: 'Game2', Game: 'Basketball' },
{ Id: 'Game3', Game: 'Cricket' },
{ Id: 'Game4', Game: 'Football' },
{ Id: 'Game5', Game: 'Golf' },
{ Id: 'Game6', Game: 'Hockey' },
{ Id: 'Game7', Game: 'Rugby' },
{ Id: 'Game8', Game: 'Snooker' }
];
var comboBoxObj = new ej.dropdowns.ComboBox({
// set the height of the popup element
popupHeight: '230px',
dataSource: sportsData,
allowFiltering: true,
fields: { value: 'Game' },
filtering: function (e) {
var dropdown_query = new ej.data.Query();
// frame the query based on search string with filter type.
dropdown_query = (e.text !== '') ? dropdown_query.where('Game', 'startswith', e.text, true) : dropdown_query;
// pass the filter data source, filter query to updateData method.
e.updateData(sportsData, dropdown_query);
},
// set the placeholder to ComboBox input element
placeholder: 'Select a game',
});
comboBoxObj.appendTo('#games');
});
})
function onfiltering(e) {
debugger;
}
</script>
<style>
#wrapper {
width: 20%;
}
.disableSelection {
pointer-events: none;
}
</style>
|
Hi Dan,Thanks for your update.Based on your shared information, we suspect that your service data is not loaded when pass the update data parameter. We have modified the attached sample based on your scenario. Please refer the below code to resolve the issue.Sample code example.
<div id="wrapper"><button id="btn">Click to append table</button></div><script type="text/javascript">document.addEventListener("DOMContentLoaded", function (args) {document.getElementById('btn').addEventListener('click', function () {var table = document.createElement('table');for (var i = 1; i < 2; i++) {var tr = document.createElement('tr');var td1 = document.createElement('td');var td2 = document.createElement('td');var text1 = document.createElement('input');text1.setAttribute('id', 'games');var text2 = document.createTextNode('Text2');td1.appendChild(text1);td2.appendChild(text2);tr.appendChild(td1);tr.appendChild(td2);table.appendChild(tr);}document.getElementById('wrapper').appendChild(table);var sportsData = [{ Id: 'Game1', Game: 'Badminton' },{ Id: 'Game2', Game: 'Basketball' },{ Id: 'Game3', Game: 'Cricket' },{ Id: 'Game4', Game: 'Football' },{ Id: 'Game5', Game: 'Golf' },{ Id: 'Game6', Game: 'Hockey' },{ Id: 'Game7', Game: 'Rugby' },{ Id: 'Game8', Game: 'Snooker' }];var comboBoxObj = new ej.dropdowns.ComboBox({// set the height of the popup elementpopupHeight: '230px',dataSource: sportsData,allowFiltering: true,fields: { value: 'Game' },filtering: function (e) {var dropdown_query = new ej.data.Query();// frame the query based on search string with filter type.dropdown_query = (e.text !== '') ? dropdown_query.where('Game', 'startswith', e.text, true) : dropdown_query;// pass the filter data source, filter query to updateData method.e.updateData(sportsData, dropdown_query);},// set the placeholder to ComboBox input elementplaceholder: 'Select a game',});comboBoxObj.appendTo('#games');});})function onfiltering(e) {debugger;}
</script><style>#wrapper {width: 20%;}.disableSelection {pointer-events: none;}</style>Regards,Sureshkumar P
We can set the value of a select box using Javascript using the following. Suppose we have the following select box −
<select id="my-select" value="1"> <option value="1">Select</option> <option value="2">Apple</option> <option value="3">Strawberry</option> <option value="4">Cherry</option> <option value="5">Guava</option> </select>
To set the value of this select element, we need to access it using querySelector. Then set the value. For example −
// Search the select box const mySelectBox = document.querySelector('#my-select'); // Set the value to 3 or Strawberry mySelectBox.value = 3;
|
[sample]
<select id="games">
<option value="Game1">American Football</option>
<option value="Game2">Badminton</option>
<option value="Game3">Basketball</option>
<option value="Game4">Cricket</option>
<option value="Game5">Football</option>
<option value="Game6">Golf</option>
<option value="Game7">Hockey</option>
<option value="Game8">Rugby</option>
<option value="Game9">Snooker</option>
<option value="Game10">Tennis</option>
</select>
[script section]
<script>
let comboBoxObj: ComboBox = new new ej.dropdowns.ComboBox({
// set the height of the popup element
popupHeight: "230px",
// set the placeholder to ComboBox input element
placeholder: "Select a game"
});
comboBoxObj.appendTo("#games");
document.getElementById("btn").addEventListener("click", function () {
var comboObject = document.getElementById("games").ej2_instances[0];
comboBoxObj.value = "Game2";
});
</script>
|