Search code examples
kendo-uikendo-dropdown

initially loading the localdatasource while changing dropdown loading server side data in kendo


I have a small requirement i.e initially i want to load the Local DataSource to DropDownList. while changing DropDownlist i want to load Server Side DataSource. If it is possible to do.


Solution

  • try this,

    <div id='parentDiv'><div id='dropDown'></div></div>
    
    <script type='text/javascript'>
    
     $(document).ready(function() {
                    var data = [
                        { text: "Black", value: "1" },
                        { text: "Orange", value: "2" },
                        { text: "Grey", value: "3" }
                    ];
    
                    // create DropDownList from input HTML element
                    $("#dropDown").kendoDropDownList({
                        dataTextField: "text",
                        dataValueField: "value",
                        dataSource: data,
                        index: 0,
                        change: onChange
                    });
    
     function onChange(e)
     {
    
        var serachActionUrl="url";
        $.ajax({
            url: serachActionUrl,
            type: "POST",
            data: { Id: Id},
            traditional: true,
            success: function (result) {
             $('#dropDown').remove();
             $("<div id='dropDown'/>").appendTo('#parentDiv').kendoDropDownList({
                  dataTextField: "text",
                  dataValueField: "value",
                  dataSource: result,
                  index: 0,
                  change: onChange
              });
            }
        });
    
    
    </script>
    

    from the server sidesend the json data