Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toArray creates a fake root instead of using the existing root of the ordered list #81

Open
Levure opened this issue Mar 13, 2013 · 2 comments

Comments

@Levure
Copy link

Levure commented Mar 13, 2013

Hello !

When using a nested list which contains a root list-item like this :

<ol class="sortable">
  <li id="list_6010"><div><span class="disclose"><span></span></span>Home</div>
    <ol>
      <li id="list_10800">
        <div><span class="disclose"><span></span></span>One page</div>
      </li>
      <li id="list_10100">
        <div><span class="disclose"><span></span></span>One another page</div>
        <ol>
          <li id="list_10471">
            <div><span class="disclose"><span></span></span>One sub-page</div>
          </li>
        </ol>
      </li>
    </ol>
  </li>
</ol>

nestedSortable has been instanciated like this :

$('ol.sortable').nestedSortable({
  forcePlaceholderSize: true,
  handle: 'div',
  helper: 'clone',
  items: 'li',
  opacity: .6,
  placeholder: 'placeholder',
  revert: 250,
  tabSize: 25,
  tolerance: 'pointer',
  toleranceElement: '> div',
  maxLevels: 4,

  isTree: true,
  expandOnHover: 700,
  startCollapsed: false,
  protectRoot: true
});

The toArray function creates a fake root item instead of using the existing one in the ordered list.

I also tried to indicate the rootID to nestedSortable by using the rootID option like this (see under) without more success. This option makes the "fake root" to use the 'ol.sortable li:first-child' id, which then is showed twice : in the "fake root" (index 0) and in the real root (index 1)

rootID: $('ol.sortable li:first-child').attr('id')

How can I avoid that behavior ? Otherwise, it will create an extra root item each time the user will use the nestedSortable interface. Skipping the fake root while storing the tree in db will make me to have a root with a left index of 2 instead 1.

'0' ...
    'item_id' ...
    'parent_id' => "none"
    'depth' => "0"
    'left' => "1"
    'right' => "10"
'1' ...
    'item_id' => "6010"
    'parent_id' ...
    'depth' => "1"
    'left' => "2"
    'right' => "9"
'2' ...
    'item_id' => "10800"
    'parent_id' => "6010"
    'depth' => "2"
    'left' => "3"
    'right' => "4"
'3' ...
    'item_id' => "10100"
    'parent_id' => "6010"
    'depth' => "2"
    'left' => "5"
    'right' => "8"
'4' ...
    'item_id' => "10471"
    'parent_id' => "10100"
    'depth' => "3"
    'left' => "6"
    'right' => "7"

I wish, if possible, to keep the toArray function, since it provides me left and right index for storing the tree in database.

Many thanks in advance for your tips !

@mjsarfatti
Copy link
Owner

Hello,
sorry for the late answer.
Would the following workaround be acceptable?

<ol>
  <li id="list_6010"><div><span class="disclose"><span></span></span>Home</div>
    <ol class="sortable">
      <li id="list_10800">
        <div><span class="disclose"><span></span></span>One page</div>
      </li>
      <li id="list_10100">
        <div><span class="disclose"><span></span></span>One another page</div>
        <ol>
          <li id="list_10471">
            <div><span class="disclose"><span></span></span>One sub-page</div>
          </li>
        </ol>
      </li>
    </ol>
  </li>
</ol>

Here I simply set the sortable to the ol contained in the real root item.

@krissanawat
Copy link

you should notify to everyone to use exclude root in 2.0 I use stable version then stuck on this on more day

hmhofman pushed a commit to hmhofman/nestedSortable that referenced this issue Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants