Obtain/Determine data represented after appends and other drag and drops

3 posts, 0 answers
  1. RichardAD
    RichardAD avatar
    105 posts
    Member since:
    Feb 2012

    Posted 29 Mar 2012 Link to this post

    Consider a tree built by drag and drop.  Dropped nodes are added to the tree.  Then the user uses tree drag and drop to rearrange and/or change level of the tree nodes.

    How would I obtain the 'data' the that the treeview is currently presenting ?

    Thanks,
    Richard
  2. RichardAD
    RichardAD avatar
    105 posts
    Member since:
    Feb 2012

    Posted 30 Mar 2012 Link to this post

    After a bit of knocking about in the TreeView source, I think the following will deliver the data being show in the treeview
        function treeToData (tree) {
            var items = [];
            var $items = tree.find('> .k-item');
            $items.each( function(index,item) {
                items.push (itemToData (item));
            });
            return items;
        }
        function itemToData(item) {
            var text = $(item).find('> div > span.k-in').text();
            var group = {
                text: text,
                items: treeToData ($(item).find('> .k-group'))
            };
            return group;
        }
     
    var treedata = treeToData ($('#var-tree1'));alert(JSON.stringify(treedata));

  3. Kendo UI is VS 2017 Ready
  4. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 27 Apr 2012 Link to this post

    Richard,

    Thanks for this.  I've been needing to implement this precise functionality.  I'll give your functions a try.

    Thanks,

    King Wilder
Back to Top