Saturday, January 9, 2021

Kendo DropDownList Example

This article is an example of the Kendo DropDownList Component. The framework used is the Kendo UI for jQuery. In this example, we are tasked to create a drop down list.

Here are the requirements:

  1. Have a separator between the options.
  2. Don't show the "Select Option" text with the list.

Here is our solution. You can edit the code below using any text editor but I prefer Visual Studio Code. Make sure you are connected to the Internet because the code pulls the Kendo library from the Telerik CDN. Take note that this is just a demonstration code and you'll need to purchase a license if you are going to use Kendo UI for jQuery for more than just evaluation purposes.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Kendo UI DropDownList Example</title>

    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.2.617/styles/kendo.default-v2.min.css"/>

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2020.2.617/js/kendo.all.min.js"></script>
</head>
<body>
  
<input id="customers" style="width: 400px" />
<script>
    $(document).ready(function() {
        $("#customers").kendoDropDownList({
            dataTextField: "option",
              optionLabel: "Select Option",
            height: 400,
            dataSource: {
                data: [
                  {group: "group1", option: "Sum"},
                  {group: "group1", option: "Count"},
                  {group: "group1", option: "Average"},
                  {group: "group1", option: "More Aggregate Options"},
                  {group: "group2", option: "Index"},
                  {group: "group2", option: "% of Grand Total"},
                  {group: "group2", option: "More Calculation Options"},
                  {group: "group3", option: "Number Format"}
                ],
                group: { field: "group" }
            },
          open: function (e) {
           $('.k-group-header').css("display", "none");
           $('.k-group').css("display", "none");
           $('.k-list-optionlabel').css("display", "none");
          }
        });
    });
</script>

</body>
</html>

Open the HTML file in a browser and you should see an output similar to the one shown below.

Kendo DropDownList
Kendo DropDownList Example

 

If we don't handle the open event then it would look like this. Go ahead try it.

Kendo DropDownList
Kendo DropDownList

 

There you have it. A quick and simple example of how to use the Kendo DropDownList component.

No comments:

Post a Comment