Search code examples
jquerykendo-uikendo-dropdown

Kendo DropDownList requestEnd push value undefined


I have a DropDownList initialize via the data- attributes. I need to add an item to the list but the code I'm using displays the value as 'undefined' after I push the new option.

Here is my element using the data- attributes (works fine):

 <select id="#people_list"
     name="person_id"
     class="form-control"
     data-role="dropdownlist"
     data-source="datasource_people"
     data-option-label="Select A Name"
     data-auto-bind="true"
     data-text-field="name"
     data-value-Field="name"
     data-ignore-case="true"
     data-filter="startswith"
     >
     </select>

Here is my datasource params (works fine):

datasource_people = new kendo.data.DataSource({
        type: "json",
        serverFiltering: true,
        transport: {
            read: {
                dataType: 'json',
                type: 'GET',
                url: '/restful/people/'
            }
        },
        filter: {
            field: "status",
            operator: "eq",
            value: 1
        },
        schema: {
            data: function(response) {
                return response.data.people;
            },
            model: {
                id: "person_id",
                fields: {
                    person_id: {type: "number"},
                    name: { type: "string"}
                }
            },
            errors: "error",
            total: function(response) {
                return response.data.total;
            }
        }
    });

Then Later (doesn't work - adds new item as 'undefined'):

$("#people_list").kendoDropDownList({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: {
        datasource_people,
        requestEnd: function (e) {
            e.response.push({text: "John", value: "John"});
        }
    }
});

Solution

  • Looked through some of the docs for other methods and this worked perfect.

    $("#people_list").getKendoDropDownList().dataSource.insert({
        person_id: "John",
        name: "John"
    })
    

    Thanks