Reputation: 191
I have a requirement where I need to sort the rows of the plupload. I added the code (sortable : true)
and now it is working. Now I want to know the order of the sorting.
Any help would be appreciated.
Upvotes: 2
Views: 760
Reputation: 9111
If using the Plupload 2.1 jQuery UI widget:
uploader.bind('BeforeUpload', function (up, file) {
var index = $('#uploader_filelist li').index($('#' + file.id));
});
Upvotes: 0
Reputation: 15413
You may try, on FilesAdded, to add a initialIndex
property to the files object. And query this property later on the files objects to know which ordering has been performed.
Assuming uploader
is :
var uploader = $('#uploader').plupload('getUploader');
then
// add initialIndex property on new files, starting index on previous queue size
uploader.bind('FilesAdded', function(up,files){
for(var i = 0, upPreviousSize = up.files.length - files.length, size = files.length; i<size; i++)
{
files[i]["initialIndex"] = i +upPreviousSize ;
}
//console.log(up.files);
});
// remove the 'holes' in the sequence when removing files
// (if not, next files adding would introduce duplicate initialIndex)
uploader.bind('FilesRemoved', function(up,files){
// process removed files by initialIndex descending
var sort = function(a,b){return b.initialIndex - a.initialIndex;};
files.sort(sort);
for(var i = 0, size = files.length; i<size; i++)
{
var removedFile = files[i];
// update the remaining files indexes
for (var j =0, uploaderLength = up.files.length; j<uploaderLength; j++)
{
var remainingFile = up.files[j];
if(remainingFile["initialIndex"] > removedFile["initialIndex"])
remainingFile["initialIndex"]--;
}
}
//console.log(up.files);
});
Upvotes: 2