Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI sortable & selectable

Does anybody know how to combine jQuery UI selectable and sortable ? This script: http://nicolas.rudas.info/jquery/selectables_sortables/ doesn't work in Chrome and it also has plugin modifications.

like image 607
minnur Avatar asked Aug 02 '10 18:08

minnur


People also ask

How to use sortable in jQuery?

jQueryUI Sortable. jQueryUI sortable() method is used to re-order elements in the list or grid form, by using the mouse. The sorting ability of this method is based on an operation string passed as the first parameter.

What is UI sortable?

ui-sortable-handle : The handle of each sortable item, specified using the handle option. By default, each sortable item itself is also the handle. ui-sortable-placeholder : The element used to show the future position of the item currently being sorted.

What is sortable js?

Sortable JS is a Javascript library that enables you to sort lists by dragging and dropping list items. It also supports Javascript frameworks such as Meteor, AngularJS, React, Vue and Ember.


2 Answers

Just found this very easy solution from rdworth:

CSS:

ul { width: 300px; list-style: none; margin: 0; padding: 0; } li { background: white; position:relative;margin: 1em 0; padding: 1em; border: 2px solid gray; list-style: none; padding-left: 42px; } li .handle { background: #f8f8f8; position: absolute; left: 0; top: 0; bottom: 0; padding:8px; } .ui-selecting { background: #eee; } .ui-selecting .handle { background: #ddd; } .ui-selected { background: #def; } .ui-selected .handle { background: #cde; } 

HTML:

<ul id="list">     <li>Item 1</li>     <li>Item 2</li>     <li>Item 3</li>     <li>Item 4</li>     <li>Item 5</li> </ul> 

Javascript:

$( "#list" )     .sortable({ handle: ".handle" })     .selectable({ filter: "li", cancel: ".handle" })     .find( "li" )         .addClass( "ui-corner-all" )         .prepend( "<div class='handle'><span class='ui-icon ui-icon-carat-2-n-s'></span></div>" ); 

See: this fiddle.

like image 191
mhu Avatar answered Sep 17 '22 18:09

mhu


http://jsfiddle.net/t9YTB/

This is as much as i can give u :) but the idea is there. its not alllll complete but hopefully u can play about with the values and see how it goes from there :)

like image 44
Val Avatar answered Sep 20 '22 18:09

Val