Add Item To kendoDropDownList

Hector picture Hector · May 12, 2015 · Viewed 14.2k times · Source

I am trying to add a item to the kendoDropDownList, it seems to add the option but not set the value and text. Inspecting the select it just adds a new option

 <option></option>

Here is what I am using

 $("#nameList").data("kendoDropDownList")
     .dataSource.add({ "text": "Joe", "value": "Joe" });

UPDATE

Here is my datasource model and the requestEnd as suggested but the values seem to get messed up

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.plaintiffs;
            },
            model: {
                id: "person_id",
                fields: {
                    person_id: {type: "number"},
                    name: { type: "string"}
                }
            },
            errors: "error",
            total: function(response) {
                return response.data.total;
            }
        }
    });

Then Later

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

Answer

Hector picture Hector · May 13, 2015

After some searching it was quite simple but this worked for exactly what i needed.

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