Ok, so I've been working on this for quite some time now and I have yet to achieve the desired results.
I found this somewhat helpful little thread:
http://forum.jquery.com/topic/trigger-sortable-update-functionUnfortunately it doesn't really answer my question. It pointed me in what I feel is the right direction, but I haven't arrived at my desired result yet.
This is what I've got so far, but it doesn't work the way I expect it to (it does nothing at all and throws no errors):
- /* This is my CSS */
- /* Basic reset -- outline for debugging */
- * {padding: 0px; margin: 0px; outline: 1px solid rgba(0,0,0,0.1);}
- html {width: 100%; height: 100%;}
- body {width: 100%; height: 100%;}
- /* Main styles */
- .containerDiv {
- overflow-x: scroll;
- overflow-y: hidden;
- width: 800px;
- height: 600px;
- white-space: nowrap;
- float: left;
- }
- .itemDiv {
- width: 200px;
- height: 500px;
- display: inline-block;
- }
- .navBar ul, .navBar li {
- display: inline;
- }
- <!-- This is my HTML -->
- <div class="navBar">
- <ul>
- <li id="nav1">Navigation 1</li>
- <li id="nav2">Navigation 2</li>
- <li id="nav3">Navigation 3</li>
- </ul>
- </div>
- <div class="containerDiv">
- <div class="itemDiv" id="item1">Item 1</div>
- <div class="itemDiv" id="item2">Item 2</div>
- <div class="itemDiv" id="item3">Item 3</div>
- </div>
- /* This is my JavaScript */
- // Make containerDiv children sortable on X-axis
- $(".containerDiv").sortable({
- axis: "x"
- });
- // Make nav children sortable on x-axis
- $(".navBar").sortable({
- axis: "x",
- items: "li"
- });
- // Bind sorting of each (.navBar li) to its corresponding (.containerDiv .itemDiv):
- $(".navBar li").bind("mouseup", function(event,ui){
- // If I use "sortupdate" I get little to no response. If I use "mouseup",
- // I can at least get an alert to return the value of thisId.
- // Note: I am sad that console.log is blocked in Firefox,
- // because its DOM inspector is better than Chrome's
- // the (.navBar li) have ids of "nav1, nav2" and so on,
- // and the (.containerDiv .itemDiv) have corresponding ids of "item1, item2"
- // which is my way of attempting to make it easier to link them.
- // This line is my attempt to target the (.containerDiv .itemDiv) which directly
- // corresponds to the (.navBar li) which is currently being sorted:
- var tempId = "#" + $(this).attr('id').replace("nav","item");
- // When this (.navBar li) is updated after a sort drag,
- // trigger the "sortupdate" event on the corresponding (.containerDiv .itemDiv):
- $(tempId).trigger("sortupdate");
- });
I've politely waited without complaint for almost a week for some kind of acknowledgement or reply but received none. Does anyone have the ability to help me here, or should I be asking somewhere else?
EDIT1:
Just to prove that I'm doing my research, I've found several interesting and possibly helpful Stackoverflow threads related to my needs, but despite trying various assortments of what I've read and what I have, I still have not arrived at a workable solution. Here are links to the threads I've looked at:
http://stackoverflow.com/questions/3104961/dragging-multiple-list-items-simultaneously(It's close to what I'm looking for, but not quite. I am not looking to drag from one list to another.)
http://stackoverflow.com/questions/3257925/jquery-draggable-sortable-how-to-tell-if-item-was-actually-added-to-my-sortab(The receive event only works for two linked sortables. I'm not looking to link sortables in the usual way of drag and drop between them, so I can't use it -- unless the receive event fires regardless of the origin of the draggable, but the stop event and sortupdate event should work just as well for my use case.)
http://stackoverflow.com/questions/1094156/sorting-multiple-items-at-the-same-time-using-jquery-ui(Not quite what I'm trying to achieve. I'm not looking to drag more than one element at a time, but who knows, I may be asked to add that functionality soon.)
http://stackoverflow.com/questions/1718851/jquery-ui-sortable-multi-item-select(Similar to previous.)
http://stackoverflow.com/questions/1997454/is-it-possible-to-link-two-jquery-ui-draggables-together(I might give this idea a chance, but I'm not sure how to tell the other sortable that I want it to put the dragged item in between the two onto which I would be dropping it.)
It's worth noting that I not only want to have the sorting reciprocated between sortables, but I also want to still be able to take advantage of the serialize functionality so I can save their positions to a database for later use.