Kendo Context menu :datasource is not updated

2.2k Views Asked by At

We try to add the context menu item dynamically.but if we append the item to context menu it does not added to datasource of context menu it only added to menu.We need to add the item to datasource.how to resolve this?

Script

    $(document).ready(function () {
        var menu = $("#context-menu").kendoContextMenu({
            target: "#test",
            dataSource:[{ text: "item 1", key: "item1" },{ text: "item 2", key: "item2" }]
        }).data("kendoContextMenu");
        menu.append({ text: "item 3", key: "item3" })
    });

HTML

 <div id="wrapper">
   <div id="test">Right Click Me!</div>
</div>
<ul id="context-menu"></ul>
1

There are 1 best solutions below

1
On

Despite the way you've initialized it in code, the Kendo UI DataSource object is not an array. To append a data item to it, you must use its add() method. API Reference.

menu.dataSource.add({ text: 'item 3', key: 'item3' });