My Code
Need to By default set item to "ALL"
placeholder="Select" popupHeight="220px" allowFiltering="true" focus="addNullDesignation">
Need to By default Show item to "ALL"
My Code
Need to By default set item to "ALL"
placeholder="Select" popupHeight="220px" allowFiltering="true" focus="addNullDesignation">
Need to By default Show item to "ALL"
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 18, 2024, 4:21 AM EST
To set the default selected item to “ALL”, you can add a line of code to select the “ALL” item after adding it. Here’s how you can modify your
addNullDesignationfunction:function addNullDesignation() { if (!focusNullDesignation) { var dropObject = document.getElementById("drpDesignationGroup")["ej2_instances"][0]; // Add "ALL" item at the first position dropObject.addItem({ Value: 0, Text: "ALL" }, 0); // Add "Null Designations" item at the second position dropObject.addItem({ Value: -1, Text: "Null Designations" }, 1); // Set the selected item to "ALL" dropObject.value = 0; // Update the dropdown list dropObject.dataBind(); } focusNullDesignation = true; }This will set the default selected item to “ALL” when the dropdown list is focused. The
dropObject.value = 0;line sets the selected item to the one with a value of 0, which is “ALL”.Sachin SinghRank #66 · 26.2K reputationPosted Jan 18, 2024, 4:36 AM EST
you just need to assign the value of the option you want as selected, as in your case you want "ALL" so do this
dropObject.value = 0;Mithun Pradhan194 reputationPosted Jan 18, 2024, 5:02 AM EST
Set dropObject.value = 0; Not working
var focusNullDesignation = false;
function addNullDesignation() {
if (!focusNullDesignation) {
var dropObject = document.getElementById("drpDesignationGroup")["ej2_instances"][0];
// Add "ALL" item at the first position
dropObject.addItem({ Value: 0, Text: "ALL" }, 0);
// Add "Null Designations" item at the second position
dropObject.addItem({ Value: -1, Text: "Null Designations" }, 1);
// Set "ALL" as the default selected item using the value property
dropObject.value = 0;
// Update the dropdown list
dropObject.dataBind();
}
focusNullDesignation = true;
}
screenshot my output
Actual Need to
Sachin SinghRank #66 · 26.2K reputationPosted Jan 18, 2024, 5:09 AM EST
Then check with the index property
dropObject.index = 0;var focusNullDesignation = false; function addNullDesignation() { if (!focusNullDesignation) { var dropObject = document.getElementById("drpDesignationGroup")["ej2_instances"][0]; // Add "ALL" item at the first position dropObject.addItem({ Value: 0, Text: "ALL" }, 0); // Add "Null Designations" item at the second position dropObject.addItem({ Value: -1, Text: "Null Designations" }, 1); // Set the default selected index to 0 (for "ALL") dropObject.index = 0; // Update the dropdown list dropObject.dataBind(); } focusNullDesignation = true; }