1

I have the following code:

    var cnt = 0;
    $(document).ready(function () {
        var data = [
            {
                "id":  cnt++,
                "text":"node_" + cnt
            }
        ];
        var tree = $("#treeview").kendoTreeView({
            dataSource:kendo.observableHierarchy(data)
        }).data("kendoTreeView");

        $("#push").click(function () {
            var pos = tree.dataItem(tree.select());
            pos.items.push({id:cnt++, text:"node_" + cnt});
        });

        $("#append").click(function () {
            var pos = tree.select();
            tree.append({id:cnt++, text:"node_" + cnt}, pos);
        });

        $("#show").click(function () {
            var data = tree.dataItem(".k-item:first");
            $("#content").html(JSON.stringify(data, null, 2));
        });
    });

And there are two functions: 1. push: once selected a node in the tree, it uses dataItem to get current data item and pushes one additional node into it (child node). This should be valid since dataSource is an ObservableHierarchy object. 2. append: once selected a node in the tree, it uses append to introduce one additional node into it (child node). This was valid on previous release of KendoUI and modify the tree but should not reflect changes in the DataSource.

The question / problem is: 1. If I use append the tree is update (visually) but the dataItem is not updated. 2. If I use push then dataItem is update but not the tree. 3. If I select a node, use append and then push, the tree is visually updated and the model too.

It seems that the first time that I introduce a child append updates some internal structure and from there the tree 'observes' the observable hierarchy put if I directly push it then the tree does not observe the observable hierarchy.

How should I insert nodes dynamically being able to check the DataSource and get the current state of the tree?

NOTE This is with the latest version of KendoUI Q2.1024.

OnaBai
  • 40,767
  • 6
  • 96
  • 125

2 Answers2

1

Ok so,I just got an answer on a ticket about this matter after 2 days. It is indeed a BUG which is already fixed in the latest builds,but the builds are only available for customers with an active subscription...

It will be available for the rest of the community in the next official release (around March 2013).So currently the only solution is to purchase a commercial subscription and you will get immediate access to the new builds...

Kinda disappointed with all this commercial stuff since it is a bug..But anyway,nothing we can do about it.. At least we know we are not crazy,and in a few months we can replace our code with the fixed build. :P

CipherDarkness
  • 214
  • 1
  • 8
  • 18
  • Any good idea for that?I though maybe I can `.insert` to the datasource along with every .append but I haven't tested it yet.. – CipherDarkness Nov 29 '12 at 15:45
  • I´ll take a look into the code but I'm pretty bussy for the next two weeks so I don't know when I can get back to it. – OnaBai Nov 29 '12 at 15:51
  • I see,I'll try it out the next few days probably,if I have something new I'll post here,if you can do that too please – CipherDarkness Nov 30 '12 at 09:33
0

Kinda my problem too at the moment since append doesn't update the dataSource at all and while push updates the dataSource,it does so only the first time I add a node,I can't even select that node afterwards until I save the dataSource and refresh the page.(or I get an pos.items is undifined error)

What I've though so far is that maybe we can use the push method that adds the child-node to the dataSource and try to force load the selected node's children in the dataSource everytime through treeview.dataSource.get(treeview.select()).load()

According to documentation here http://docs.kendoui.com/documentation/api/framework/node

If we can get the selected Node we can load it's children forcibly.But I haven't been able to have datasource.get() or dataSource.view()[] read the selected node so far..

PS I know this is not a complete answer but maybe it helps..

CipherDarkness
  • 214
  • 1
  • 8
  • 18
  • Yes @CipherDarkness, we can try some type of workaround like what you propose but it is not *the solution*. I'm still waiting for some KendoUI support guy to say if it is a *feature* or a *bug* and in the meantime see if SO community has some *elegant* workaround that always works... – OnaBai Nov 15 '12 at 07:50
  • I see, let's hope the Kendo Support replies..However if you find some work around for this please post here too.Thx – CipherDarkness Nov 15 '12 at 08:58
  • Kendo Support replied that the latest version solved the problem but actually nothing changed. So far there is no solution other than implement it trapping drag, drop,... events – OnaBai Nov 21 '12 at 23:02
  • I know,I'm the one who posted on that post in the forums with you and I asked too but they didn't even seem to reply to us in the first place :/ – CipherDarkness Nov 22 '12 at 08:08
  • About the issue,indeed append doesn't work but I found out something that doesn't solve the problem but changes it a bit..As I said in kendo forums, `treeview.append` seems to work only when the node already has other children.And `dataItem.push` seems to work on the dataSource but I can't access the node created unless I save the DS and reload the page..However I tried `treeview.dataItem(treeview.select()).append` which seems to work on nodes having already children and in new nodes!But it doesn't work on old nodes with no children...I believe this has to do with the initialization of `items` – CipherDarkness Nov 22 '12 at 08:15
  • I'll post details about this here: http://stackoverflow.com/questions/13497232/kendo-ui-delete-a-node-attribute-in-treeview#comment18481657_13497232 – CipherDarkness Nov 22 '12 at 08:16