3

I'm using jQuery plugin Nestable for menus editor. I want all menu items to auto collapse, but also to expand when a user clicks on each expandable icon.

Here is jQuery Nestable plugin.

 $(document).ready(function(){
   $("#product_list").nestable({
      maxDepth: 10,
      collapsedClass:'dd-collapsed',
   });
 });
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
DMS-KH
  • 2,669
  • 8
  • 43
  • 73

3 Answers3

13

Since there isn't much option available in this plugin what you can do is manually collapse once the nestable has been created as below:

$(document).ready(function(){
   $("#product_list").nestable({
      maxDepth: 10,
      collapsedClass:'dd-collapsed',
   }).nestable('collapseAll');//Add this line
   //$("#product_list").nestable('collapseAll') //Or this
});

DEMO with expanded view without collapsing on load and

DEMO with collapsed view on load

Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200
0

To expand on the auto-collapse which Guruprasad had a good answer for, here is a simple way to remove all collapsed, equivalent to what your 'Collapse All' button would do.

$(".dd-collapsed").removeClass("dd-collapsed");
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Stephen85
  • 250
  • 1
  • 15
0

Just call the function:

$('.dd').nestable('collapseAll');
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34