jQuery plugin to sorting lists also the tree structures.

Overview

jquery-sortable-lists

jQuery plugin to sorting lists also the tree structures.

$('#myList').sortableLists( options );

You can sort an items of html lists by mouse. Create tree structures. Format css of all active items however you want. You can define the isAllowed callback which determines if dragged item can be inserted into another. Set the insert zone like a distance which determines if item will be inserted inside or outside of the active area, also insert zone plus feature, speed of autoscroll function, max levels number... speed of autoscroll function, max levels number... Available is onDragStart and complete callback.

Now plugin supports also mobile devices. Link jquery-sortable-lists-mobile.js instead of jquery-sortable-lists.js.

Sortable lists also contains export functions toArray, toHierarchy, toString.

For more info look at the documentation.

Changelog is here.

Comments
  • MaxLevels not working

    MaxLevels not working

    Hello @camohub! Thanks for a great plugin, this has saved me hours of dev work. :)

    One issue though: the maxLevels options is not working. When I set it to a number, it stops nesting altogether. If I remove the maxLevels option (it defaults to false), it starts nesting again.

    Please advise. Thanks!

    opened by lulubytt 12
  • Nest item under others above it by dragging right.

    Nest item under others above it by dragging right.

    Hi! Checking this out.

    I noticed that if an item is already below other items in a group. Then dragging it right does not nest it under the item above it. Possible/How? Thx!

    Example:

    item1 item2 item3

    drag item3 right

    item1 item2 -> item3

    dragging item3 right does not nest it under the above item, item2

    Currently you have to drag it on top of a group of items above it.

    And if it's already the bottom item, then it's not something a user might quickly understand to do. They may just try to drag it to the right. Since it's already below that item.

    How can I do? Thx!

    opened by WriterStat 11
  • "insert on hover" feature

    As far as I see, inserting nested element is based on insertZone threshold currently. User has to move the mouse some distance from the left edge of the element and if this distance is above the threshold, dragged element is inserted as a child to hovered one.

    We could add optional feature that allows to change (or extend) this behavior (from UX perspective): when user hovers the element, dragged one becomes its child. In my case all attempts to simulate this by changing insertZone made widget unusable (ex. when value is 0 there was no way to reorder elements).

    Technically we may reuse the mechanism and create something like 'vertical insert zone'. If the mouse is close enough to the vertical center of hovered element, dragged one will become its child when dropped, otherwise elements are reordered.

    See attached image for explanation. sortable_design

    What do you think?

    question 
    opened by erykpiast 9
  • complete is called after each click and not only after a drop to another position

    complete is called after each click and not only after a drop to another position

    I would like to persist the menu in case the position was changed after a drop. I implemented this in the 'complete' callback but I see that this callback is also called after just clicking a menu-item and not only after a drop to another position as expected.

    question 
    opened by dirkjacobs 9
  • HTML content opener

    HTML content opener

    Add functionality to use HTML code for the open and close openers content by setting opener.as = 'html', allowing for example to use font-awesome icons by writing options like this :

        options =
          ...
          opener:
            active: true
            as: 'html'
            close: '<i class="fa fa-plus"></i>'
            open: '<i class="fa fa-minus"></i>'
            openerCss:
              'float': 'left'
              'margin-left': '-27px'
              'margin-top': '1px'
              'cursor': 'pointer'
    
        $('ul#hierarchy-tree').sortableLists options
    

    opener

    opened by randoum 9
  • [Up] Opener position

    [Up] Opener position

    For info :

    On my config (in flex li) opener appear at the end if I move item on nexw submenu.

    I change :

    if ( hintWrapperNode.length )
    {
    		hintWrapperNode.prev( 'div' ).append( opener.clone( true ) );
    }
    

    by

    if ( hintWrapperNode.length )
    {
    	if( setting.opener.position == "after" )
    		hintWrapperNode.prev( 'div' ).append( opener.clone( true ) );
    	else
    		hintWrapperNode.prev( 'div' ).prepend( opener.clone( true ) );
    }
    

    And add option open.position on setting

    opened by dutom007 8
  • How can i add remove button for li element as open/close button?

    How can i add remove button for li element as open/close button?

    I want to use add and remove li list. I can add easily with jquery but i don't know how to add delete button as open/close like button. How can i do it ?

    opened by pyaehein 7
  • Add a new nested list item

    Add a new nested list item

    Hey there! Thanks for this awesome library. I am using it to implement a system where upon clicking on a button, a new list item is added to the main ul. Now, the item does get appended but it doesn't receive the icons for the openers that i set in the options. I can see the list item and it's always opened without the '+' or '-' signs so i can't open or close that particular list item. Can you let me know how that would be done as the only way i found is to re-create the Sortable List using $('element').sortableLists({ options }) but that appends the '+' and '-' icons to each and every list item multiple times

    opened by ghost 6
  • List is generated dynamically

    List is generated dynamically

    I have an ajax process where I download the hierarchy and the items first. Then I populate my list dynamically. But the collapse and expand doesn't seem to work.

    opened by kidino 6
  • Moving a child to the the outermost level not possible

    Moving a child to the the outermost level not possible

    So I'm facing a problem where if an item is child I can't move to the outermost level. For example if the list consist of one item with a child. I'm not able to make that child a sibling of it's parent. Any idea on how I can make this possible?

    opened by dgonza12 4
  • 'sortableListsPlaceholder' as id

    'sortableListsPlaceholder' as id

    Hi!

    Plugin is awsome, I have integrated successfully with no many issues but I have last one that still give me a headache.

    I have defined this callback on drop completion:

    complete: function(currEl)
                {
                    var $tree = $sortable.sortableListsToArray();
                    $.ajax({
                        url: '{{ path('admin_category_sort_component') }}',
                        type: 'POST',
                        data: { data : $tree},
                        success: function(data) {
                            //console.debug(data);
                        }
                    });
                }
    

    But sortableListsToArray function gave me an element with 'sortableListsPlaceholder':

    ...
        [order] => 0
     )
    [2] => Array
    (
        [id] => sortableListsPlaceholder
        [parentId] => 92
        [order] => 0
    )
    ...
    

    Seems sortableListsToArray is not waiting to id restore after drop completion.

    I need export tree data on drop finish in order to save hierarchy automatically.

    I'm making anything wrong maybe?

    Thanks in advance.

    opened by fjavier-moreno 4
  • Items added after initializing list with maxLevels cannot be dragged

    Items added after initializing list with maxLevels cannot be dragged

    Greetings again @camohub!

    I've noticed an issue that appeared in this new version 2.2.0. Whenever we have a sortable list initialized with some value for maxLevels, any new item that is later appended to the list cannot be dragged into a new position. I've set an example on my forking so you can see for yourself:

    https://lucaslm.github.io/jquery-sortable-lists/example3

    The reason for this error is because you changed how to compute the level an item would have when dragged to a new position. Specifically, upon initializing the list you add some data to every item, namely 'inside-levels' and 'upper-levels'.

    https://github.com/camohub/jquery-sortable-lists/blob/aba9cb1c95b9ae4e88c844c93d25e40f96e4c75c/jquery-sortable-lists-mobile.js#L181-L192

    Later on the function checkMaxLevels, you get 'upper-levels' from the new parent and 'inside-levels' from the item being dragged. You then add those to see if it exceeds maxLevels. Since items created later do not have 'inside-levels', the sum evaluates to NaN and the expression to false, even when it shouldn't.

    https://github.com/camohub/jquery-sortable-lists/blob/aba9cb1c95b9ae4e88c844c93d25e40f96e4c75c/jquery-sortable-lists-mobile.js#L989-L995

    This can be avoided if you do not insert new items, but it wasn't an issue when insideLevs was computed at startDrag for the item being dragged, and upperLevs at its dropping, though it could be less performatic.

    I suppose there are two approaches for this. We can create a new option to control how maxLevels is computed, to let the user choose whether to compute the levels on the fly ineficiently (but allowing later item insertions) or to store the levels on initialization. The other approach is to use a MutationObserver to store an item's levels each time it is included on the list's DOM after initialization.

    Let me know which approach you think is best, and I can create a pull request for this issue.

    opened by lucaslm 0
  • Add dual functionality of ignoreClass

    Add dual functionality of ignoreClass

    I have used draggable items in fix envelopes with set ignoreClass. After the jquery-sortable-lists upgrade it has stopped working and I have to freeze it to old version.

    What about some option to define ignoreClass behavior?

    Or allow to define ignoreClass and ignoreClosestClass or on other way ignoreClass and ignoreWithClass. Simply two conditions in code.

    opened by Marenek 4
  • Issue with scrolling ancestors other than the body or html elements

    Issue with scrolling ancestors other than the body or html elements

    Greetings @camohub!

    Firstly, thanks for the awesome plugin. Unfortunatelly I found an issue with it, but I believe it can be addressed. When dragging an item to the edge of the screen, it automatically scrolls the window to continuing moving the item up or down. This works mostly fine, but I noticed that when one or more ancestors of the list element also have scroll bars of their own, this becomes an issue. Here are some examples I have on my forking of the project:

    • https://lucaslm.github.io/jquery-sortable-lists/example1
    • https://lucaslm.github.io/jquery-sortable-lists/example2

    Fortunatelly, the following pull request solves this issue. I've tested it on many browsers and it seems to work. I've commited from the dev branch, which I think is the one you use for bug fixing and improvements

    https://github.com/camohub/jquery-sortable-lists/pull/61

    opened by lucaslm 5
  • Dev multiple scrolling

    Dev multiple scrolling

    Fixing issue with multiple scrolling ancestors.

    A few demonstrations of the issue can be found at:

    • https://lucaslm.github.io/jquery-sortable-lists/example1
    • https://lucaslm.github.io/jquery-sortable-lists/example2
    opened by lucaslm 0
Owner
camo
camo
Fancytree - JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Fancytree Fancytree (sequel of DynaTree 1.x) is a JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkb

Martin Wendt 2.6k Jan 9, 2023
Ordered lists, flat or nested, multiple formats ordered lists.

logseq-plugin-ol 有序列表,单级或多级、多种样式的有序列表。 Ordered lists, flat or nested, multiple formats ordered lists. 使用展示 (Usage) 在想要展示为有序列表的块上添加一个以 #.ol 开头的标签就可以了。有

Seth Yuan 25 Jan 1, 2023
This is a jquery ui sortable helper plugin for handy tree type structure sotable.

Tree Sortable A drag and drop list item sorting and level changing library. Motivation The jQuery-ui's sortable plugin allows us to sort items vertica

Sajeeb Ahamed 10 Dec 23, 2022
In this website you will add books and also watch the lists of books. A website build wit HTML, CSS, and JavaScript.

Awesome Books ES6 In this website you will add books and also watch the lists of books. Built With HTML CSS JavaScript Authors ?? HaaDiiii GitHub: @Ha

Hamid Ali 8 Oct 7, 2022
In this website you will add favorites books and also watch the lists of books. Built with JavaScript ES6 Modules

Awesome Books In this website you will add books and also watch the lists of books. Built With HTML CSS JavaScript Screen Shots Desktop Screen Tablet

Aamir khan 7 Nov 20, 2022
A single-page application that allows users to keep track of their books. Users can add the book details (book title and author) and also, and the books can also be removed. Built with JavaScript, HTML, and CSS

Project Name Awesome book with ES6 Description the project. This is a single page application that allows users to keep track of their books. Users ca

Micheal Oguntayo 4 Oct 13, 2022
JqTree - Tree widget for jQuery

jqTree JqTree is a tree widget. Read more in the documentation. Features Create a tree from JSON data Drag and drop Works on ie9+, firefox, chrome and

Marco Braak 1k Dec 22, 2022
Sorting Arrays as simple as it gets.

Sort Sorting Arrays as simple as it gets. This module is published at: https://deno.land/x/sort. Simple Usage Example import { SortService, Direction

null 11 May 12, 2022
Trying to re-create sorting alghorithms with js.

The initial idea was to re-create sorting mechanisms from scratch using low time complexity sort algorithms. Bubble, Radix and Lexographical was the

Drayan Silva Magalhães 1 Dec 19, 2021
An unreliable and overall unusable sorting library for numbers with a global cache on the edge.

unsort An unreliable and overall unusable sorting library for numbers with a global cache on the edge. the algorithm This library implements a number

Jonas Wanner 6 May 19, 2022
Path-finding & Sorting algorithms Visualizer

Update - Changelog ?? 09.05.2022 AlgoVision is now fully mobile-responsive for all its features ! On mobile, the 'Mouse Chase' option in Dynamic Mode

Eliya Shalom 23 Dec 18, 2022
Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

fast-natural-order-by Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode charac

Shelf 5 Nov 14, 2022
There can be more than Notion and Miro. Affine is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

AFFiNE.PRO The Next-Gen Knowledge Base to Replace Notion & Miro. Planning, Sorting and Creating all Together. Open-source, Privacy-First, and Free to

Toeverything 12.1k Jan 9, 2023
Implementing various sorting algorithms in Typescript's type system

Sorta Cool I was on a 10 hour flight with no WiFi, and, bored out of my mind, I thought it would be fun to implement some sorting algorithms in the Ty

Neil Ramaswamy 7 Nov 10, 2022
A table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, row context menus, dark theme, and more.

Mantine DataTable A "dark-theme aware" table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagina

Ionut-Cristian Florescu 331 Jan 4, 2023
JavaScript client-side HTML table sorting library with no dependencies required.

TABLE-SORT-JS. Description: A JavaScript client-side HTML table sorting library with no dependencies required. Demo Documentation. (work in progress)

Lee Wannacott 32 Dec 14, 2022