4

Is there a functionality in jQuery Mobile for making listviews sortable?

By sortable, I mean possibility for the user to reorder elements in the list by dragging, like on the iPhone.

Applying jQuery UI sortable effect on the listview makes it sortable on desktop browser, but not on mobile.

Update: I was trying these solutions. Touch Punch makes drag'n'drop functionality to work, but only when the list is not longer then the device screen. If some items are out of the screen (you need to scroll down to see them), then functionality gets broken: when you're dragging an item, it gets the wrong position.

Community
  • 1
  • 1
AbstractVoid
  • 3,583
  • 2
  • 39
  • 39

1 Answers1

0

An easy solution is to use jquery ui sortable along with jquery mobile list view, see the code:

<ul data-role="listview" class="sortable">
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li>
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li>
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li>
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 4</li>
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 5</li>
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 6</li>
        <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 7</li>
</ul>

and make sure you add the jqueryui library to the

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>

Then call the sortable function:

<script>
        $(function() {
                $( ".sortable" ).sortable();
                $( ".sortable" ).disableSelection();
        });
</script>

I hope this helps...

Sam Battat
  • 5,725
  • 1
  • 20
  • 29