vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.15k stars 1.38k forks source link

Droppable Node not working #2798

Open strtob opened 1 day ago

strtob commented 1 day ago

Hi,

I've searched for hours, but I can't find a solution, to drop a div on a node do not work:

 $(".jstree-node")
        .droppable({
            //accept: '.filemanager-file-row', // Accept file rows
            //hoverClass: "tree-hover",

            drop: function (event, ui) {

                // Ensure jstree is properly initialized               
                var jstreeInstance = $(this).jstree(true);
                var selectedNodes = jstreeInstance.get_selected(true); // Get selected nodes

                console.log(selectedNodes);

                if (selectedNodes.length > 0) {
                    var categoryId = selectedNodes[0].id; // Get the category ID
                    var fileId = ui.helper.data('key'); // Get the file ID

                    // Perform AJAX call to move file
                    $.ajax({
                        url: '/filemanager/category/move',
                        type: 'POST',
                        data: {
                            category_id: categoryId,
                            file_ids: [fileId] // Pass as an array
                        },
                        success: function () {
                            $.pjax.reload({ container: '#pjax-container-file' }); // Reload the grid
                            alert('File moved successfully!');
                        },
                        error: function () {
                            alert('An error occurred while moving the file.');
                        }
                    });
                } else {
                    alert('Please select a category to move the file into.'); // Alert if no category is selected
                }
            }
        });

Any ideas would be very appreaciated!

Thanks a lot, also for jstree!

Best, Tobi