Solved

Sortable (JQUI):  Don't allow items to be dragged above non sortable items.

Posted on 2014-01-13
3
266 Views
Last Modified: 2014-01-17
Ok before I write a bunch of code to catch and loop.  Any ideas on how to do this.

I have a UL that returns items.  They will always come back with "standard" items first then custom.

I have locked the standard ones down so they can't be moved/sorted in the list.  

The issue is:  I don't want any custom ones to be able to be dragged above the standard ones.  

Looks like this:
<ul id="jqWidSelected" class="jqSortableDash ui-sortable">
<li class="dBBBorBottom fixed dBBAlt" data-id="AE10BCF3-B2C0-474C-BA27-750426330529" style="height:70px;">
<li class="dBBBorBottom fixed" data-id="C30D2FAC-AE62-43D0-A833-73B5A67F2494" style="height:70px;">
<li class="dBBBorBottom dBBAlt" data-id="E0FE32F2-795E-4435-A117-EAFD28718FFD" style="height:70px;">
<li class="dBBBorBottom " data-id="8392F1B2-7115-4575-A230-611D55AC0140" style="height:70px;">
<li class="dBBBorBottom dBBAlt" data-id="066E3E2D-1182-4E39-B6BD-4BBE7659A2C3" style="height:70px;">
<li class="dBBBorBottom " data-id="2C0F5B37-824B-4D08-BFA0-1D2C0940F91F" style="height:70px;">
</ul>


NOTE:  fixed on LI determines locked or disabled

Open in new window


currently I sort with this:
    //  handle drag sort for dash order SORT
    $('.jqSortableDash').sortable({
        cancel: ".fixed",
        delay: 100,
        //connectWith: ".handleDrag",
        stop: function (event, ui) {
            p.HandleSortDash(ui, ui.item)
        },
        start: function (event, ui) { }
    }).disableSelection();

which calls this...basically just handles the order to the DB


//-------------------------    HANDLE SORT DASH   ------------------------------------------------------------ //
//
IPpage.prototype.HandleSortDash = function (ui, e) {
    var orderBy = '';

    $('#jqWidSelected li').each(function (i) {
        var n = $(this);
        n.find('.jqNum').html((i + 1));
        orderBy += '|' + n.attr('data-id');
    });
    //  update db
    this.HandleDBPreferenceCRUD(orderBy, 50);
    return;
}v

Open in new window


thanks in advance
0
Comment
Question by:skillilea
3 Comments
 
LVL 24

Expert Comment

by:lenamtl
ID: 39782279
Have you tried to use table instead of li,
there are great jQuery plugin for that kind of situation.

Footable
http://themergency.com/footable/

Datatable
http://datatables.net/
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39788610
Try changing
cancel: ".fixed",

Open in new window

to
items: ":not(.fixed)",

Open in new window

reference: http://jqueryui.com/sortable/#items

This seems to have the exact effect you want because the locked items are at the top to begin with (only tested in FireFox (but should not matter of course), on-line example here: http://schutt.nl/ee/Q_28336953/ ).
0
 

Author Closing Comment

by:skillilea
ID: 39788650
AWESOME!

Thanks tons!  Crazy simple.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now