Mithun Pradhan

Mithun Pradhan

  • 1.6k
  • 150
  • 20.6k

How to set ByDefault item value in ejs-dropdownlist ?

Jan 18 2024 8:55 AM

My Code

Need to By default set item to "ALL"
<ejs-dropdownlist id="drpDesignationGroup" cssClass="e-custom" dataSource="@Model.DataManagementDropDownsViewModel.DesignationGroupId.Items"
                  ejs-for="@Model.DataManagementDropDownsViewModel.DesignationGroupId"
                  placeholder="Select" popupHeight="220px" allowFiltering="true" focus="addNullDesignation">
    <e-dropdownlist-fields text="Text" value="Value"></e-dropdownlist-fields>
</ejs-dropdownlist>

<script type="text/javascript">
    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);
    
            // Update the dropdown list
            dropObject.dataBind();
        }
        focusNullDesignation = true;
    }
</script>

Need to By default Show item to "ALL"


Answers (4)