Dropzone images reordering
Asked Answered
S

1

7

I have used dropzone to upload multiple pictures to my server with drag and drop. First I select all my pictures and then when I want to upload, I press button and all files are uploaded.

I want to change order they are uploaded, and I am using this tips Is there a way to do drag-and-drop re-ordering of the preview elements in a dropzone.js instance? and I can change order with mouse drag.

The problem is that when I upload pictures are not uploaded in order I have changed, but they are uploaded as I have initially put them in dropzone.

My dropzone is configured as this

autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 3,
clickable: ".add",
previewsContainer: "#previews", 
maxFiles: 5,
Significative answered 21/8, 2015 at 8:3 Comment(1)
F
5

Html will be look like this:

<div id="imageUpload" class="dropzone mt-2"></div>

And add this code in js

$(".dropzone").sortable({
    items:'.dz-preview',
    cursor: 'grab',
    opacity: 0.5,
    containment: '.dropzone',
    distance: 20,
    tolerance: 'pointer',
    stop: function () {
      var queue = myDropzone.getAcceptedFiles();
      newQueue = [];
      $('#imageUpload .dz-preview .dz-filename [data-dz-name]').each(function (count, el) {           
            var name = el.innerHTML;
            queue.forEach(function(file) {
                if (file.name === name) {
                    newQueue.push(file);
                }
            });
      });
      myDropzone.files = newQueue;
    }
});

Hope that this will work.

Frederickson answered 28/10, 2019 at 5:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.