Prevent Drag and Drop between Two Trees if node exists

4 posts, 0 answers
  1. axwack
    axwack avatar
    37 posts
    Member since:
    Aug 2012

    Posted 15 Feb Link to this post

    I believe this function can work using k-denied but still not very good with the JS for the tool suite. I have two treeviews. I'm working on a screen where once a treeview is persisted to the DB, a user could go back and update it with new nodes, a reordering of nodes or deleting the nodes.

    How can I validate that if a node is dragged from the left tree to the right tree, that if the ID (identified by ext_model_id) exists, don't drop on the tree? How can I see if the node is even there? Do I use the data-uid?

     Help would be appreciated.

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 18 Feb Link to this post

    Hi Vincent,

    You can consider using the dataSource.get(id) and treeView.findByUid() methods to check whether a node with the sought id exists in the target data source. Example:

    var treeview = $("#treeview").data("kendoTreeView");
    var barDataItem = treeview.dataSource.get(2);
    var barElement = treeview.findByUid(barDataItem.uid);


    Regards,
    Genady Sergeev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. axwack
    axwack avatar
    37 posts
    Member since:
    Aug 2012

    Posted 18 Feb in reply to Genady Sergeev Link to this post

    That may not work because the hid is different between the two nodes. The left side is generated by the stored adjacency list in the db and the right side is as well. The code makes an Ajax call to get nodes. In your second is there a way to find out which level or row the node is on? I ended up solving by looking at the text and comparing.
  5. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 22 Feb Link to this post

    Hello axwack,

    Indeed, the uid may change, between reloads or if only the data is inserted when moving the item. If you have a way of identifying nodes by ID, you can get the ID of the node that is being dragged, and see if the same ID exists in the target treeview. See this Dojo snippet for a demo.

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready