jQuery disable sort by mouse

66 views Asked by At

Is there a solution to disable ui sorting by mouse drag event in jQuery? I use the function sortable but I created arrows to short. I want to disable the regular mouse drag functionality.

function moveUp(item) {
    var prev = item.prev();
    if (prev.length == 0)
        return;
    prev.css('z-index', 999).css('position','relative').animate({ top: item.height() }, 250);
    item.css('z-index', 1000).css('position', 'relative').animate({ top: '-' + prev.height() }, 300, function () {
        prev.css('z-index', '').css('top', '').css('position', '');
        item.css('z-index', '').css('top', '').css('position', '');
        item.insertBefore(prev);
    });
}
function moveDown(item) {
    var next = item.next();
    if (next.length == 0)
        return;
    next.css('z-index', 999).css('position', 'relative').animate({ top: '-' + item.height() }, 250);
    item.css('z-index', 1000).css('position', 'relative').animate({ top: next.height() }, 300, function () {
        next.css('z-index', '').css('top', '').css('position', '');
        item.css('z-index', '').css('top', '').css('position', '');
        item.insertAfter(next);
    });
}
$('.sortable').sortable({ items: '.ordering-field', distance: 10 });
$('i.sorter').click(function() { 
    var btn = $(this);
    var val = $(this).data('direction');
    console.log(val);
    if (val == 'up')
        moveUp(btn.parents('.ordering-field'));
    else
        moveDown(btn.parents('.ordering-field'));
});

Thanks.

Nicky

1

There are 1 answers

0
Irvin Dominin On BEST ANSWER

Since you are using sortable but you don't want it because you have a custom sorting experience you can set a dummy item option in order to filter on dummy elements like:

items: "foo"

In this way the element will be sortable, but non sortable.

Demo: http://jsfiddle.net/x5o72qnp/