Reputation: 54
I am using mjsarfattis nestedSortable Plugin to build a hierachical data-structure. Is there a way to prevent items from being nested? An example:
phase 1
group
item
item
subgroup
item
item
item
item
item
item
item
phase 2
group
item
item
subgroup
item
item
item
item
As you can see, (sub-)groups or items can be nested inside the phases but phases themselve should not be nested inside another phase or (sub-)group.
For this case I used the "mustBeRoot" property that handles this function: _isAllowed that had been modified a bit:
_isAllowed: function(parentItem, levels) {
var o = this.options;
// Are we trying to nest under a no-nest or are we nesting too deep?
if (this.currentItem.hasClass(o.mustBeRoot) && this._getLevel(this.placeholder) != 0) {
this.placeholder.removeClass(o.mustBeRoot).addClass(o.errorClass);
if ( this._getLevel(this.placeholder) == 1) {
this.placeholder.removeClass(o.errorClass).addClass(o.mustBeRoot);
}
this.beyondMaxLevels = 1;
} else if (parentItem == null || !(parentItem.hasClass(o.disableNesting))) {
if (o.maxLevels < levels && o.maxLevels != 0) {
this.placeholder.addClass(o.errorClass);
this.beyondMaxLevels = levels - o.maxLevels;
} else {
this.placeholder.removeClass(o.errorClass);
this.beyondMaxLevels = 0;
}
} else {
this.placeholder.addClass(o.errorClass);
if (o.maxLevels < levels && o.maxLevels != 0) {
this.beyondMaxLevels = levels - o.maxLevels;
} else {
this.beyondMaxLevels = 1;
}
}
},
Ok, this works fine if I try to drop the phase inside another phase, but if I drag it a little deeper (i.e. inside a subgroup) and drop it, it will only "climb" one level up. then I have one phase in another :-/
Phases should be root-elements only! I hope u have any ideas.
Upvotes: 0
Views: 2265
Reputation: 826
In the documentation there is an error, instead of disableNesting should be disableNestingClass. Hope that helps.
Upvotes: 1
Reputation: 269
David - You should be able to give the list item you don't want to be nested the class "no-nest". For example:
<ul id="your-list">
<li id="listItem_1"><div>Item 1</div></li>
<li id="listItem_2" class="no-nest"><div>Item 2 (No-Nesting)</div></li>
<li id="listItem_3"><div>Item 3</div></li>
<li id="listItem_5"><div>Item 5</div></li>
</ul>
I hope that helps!
Upvotes: 1