user1987162
user1987162

Reputation:

jsTree drag_check not working

I have a jsTree using the dnd plugin to allow for drag and dropping of tree items to change their position. However I have noticed that the index is wrong depending on whether you drop the item before or after an object and after googling for many hours about how to fix the index issue, I have come to the conclusion that it would be easier to disable the after unless it is the last tree node of the subset

I am using the following code to call the configure the dnd plugin:

    'dnd': {
        'drop_finish': function (data) {
            alert("hi");
        },
        'drag_check': function (data) {
            alert('hi1');
            if (data.r.attr('id') == 'RootNode') {
                return false;
            } else if (data.r.hasClass('jstree-last')) {
                return {
                    after: true,
                    before: true,
                    inside: true
                };
            } else {
                return {
                    after: false,
                    before: true,
                    inside: true
                };
            }
        }
    }

however, the hi1 never gets alerted (but the hi does after I have dropped the item) so I can still drop after elements. I have tried finding out how to get the drag check to be called and tried many things like adding the jstree-drop class and other things that have been suggested on this site but I just can't get the hi1 to be alerted.

Any help would be appreciated in solving this problem

Thanks

Upvotes: 0

Views: 1655

Answers (1)

slowkot
slowkot

Reputation: 478

it looks like "dnd" plugin is using for external drag and drop. You can use check_move to prevent moving to the last position in node:

"crrm": {
    "move": {
        "check_move": function(m) {
        var length = $(m.np).find("ul:first > li").length,
            afterLast = length == m.cp;
        if (length > 0 && afterLast) {
            return false;
        }
        return true;                            
     }
 }

Upvotes: 1

Related Questions