Edit this page

DropDownList PHP Class Overview

The Kendo UI DropDownList for PHP is a server-side wrapper for the Kendo UI DropDownList widget.

Getting Started

The Basics

There are two ways to bind a Kendo UI DropDownList for PHP:

  • Locally—Local binding binds the DropDownList to a PHP array.
  • Remotely—During remote binding the DropDownList makes AJAX requests and is bound to the JSON result.

Configuration

Below are listed the steps for you to follow when configuring the Kendo UI DropDownList for local binding.

Step 1 Make sure you followed all the steps from the introductory article on Telerik UI for PHP—include the autoloader, JavaScript, and CSS files.

Step 2 Create an array to which the DropDownList will be bound.

Example
    <?php
    $data = array(
        array('name' => 'John Doe', 'age' => 32),
        array('name' => 'Jane Doe', 'age' => 29)
    );
    ?>

Step 3 Create a DataSource and set its data.

Example
    <?php
    $dataSource = new \Kendo\Data\DataSource();
    $dataSource->data($data);
    ?>

Step 4 Create a DropDownList, configure its dataTextField and dataValueField options, and set its dataSource.

Example
    <?php
    $dataSource = new \Kendo\Data\DataSource();
    $dataSource->data($data);

    $dropdownlist = new \Kendo\UI\DropDownList('DropDownList');
    $dropdownlist->dataSource($dataSource);
    $dropdownlist->dataTextField('name');
    $dropdownlist->dataValueField('age');
    ?>

Step 5 Output the DropDownList by echoing the result of the render method.

Example
    <?php
    echo $dropdownlist->render();
    ?>

Event Handling

You can subscribe to all DropDownList events.

Specify Function Names

The example below demonstrates how to subscribe for events by specifying a JavaScript function name.

Example
    <?php
    $dropdownlist = new \Kendo\UI\DropDownList('dropdownlist');

    // The 'dropdownlist_change' JavaScript function will handle the 'change' event of the dropdownlist
    $dropdownlist->change('dropdownlist_change');

    echo $dropdownlist->render();
    ?>
    <script>
    function dropdownlist_change() {
        // Handle the change event
    }
    </script>

Provide Inline Code

The example below demonstrates how to provide inline JavaScript code.

Example
    <?php
    $dropdownlist = new \Kendo\UI\DropDownList('dropdownlist');

    // Provide inline JavaScript code that will handle the 'change' event of the dropdownlist
    $dropdownlist->change('function() { /* Handle the change event */ }');

    echo $dropdownlist->render();
    ?>

Reference

Client-Side Instances

You can reference the client-side Kendo UI DropDownList instance via jQuery.data(). Once a reference is established, use the DropDownList API to control its behavior.

Example
    <?php
    $dropdownlist = new \Kendo\UI\DropDownList('dropdownlist');
    echo $dropdownlist->render();
    ?>
    <script>
    $(function() {
        // The constructor parameter is used as the 'id' HTML attribute of the dropdownlist
        var dropdownlist = $("#dropdownlist").data("kendoDropDownList")
    });
    </script>

See Also

Other articles on Telerik UI for PHP and on the DropDownList:

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy