question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Save box state, for default collapsed and expanded boxes.

See original GitHub issue

Hi,

I’m using this solution from @BlueTeck for saving box state with localstorage https://github.com/almasaeed2010/AdminLTE/issues/1064

It’s working great as long as all the boxes on a page have the same default state, all collapsed or all expanded. I’m wondering if anyone have modified it to use it when the box is collapsed by default with collapsed-box class and expanded box.

<div class="box box-primary collapsed-box" id="filters" data-name="filters">

If boxes are all collapsed on the page I can use if(box.state == 1) instead of if(box.state == 0)

I also tried this with no luck

if(box.state == 0){
$('.box[data-name="'+box.boxname+'"]').find($.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors.collapse).trigger( "click" );
}                         
else {
  $('.box[data-name="'+box.boxname+'"]').removeClass("collapsed-box");
	} 

Any solution is welcome Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
REJackcommented, Jan 26, 2017

Your button miss the btn-box-tool class, but you can change the script to catch only .btn instead of .btn-box-tool.

That’s my button code like the preview from almasaeed2010.

<button class="btn btn-box-tool" type="button" data-widget="collapse" data-toggle="tooltip" title="" data-original-title="Collapse">
<i class="fa fa-minus"></i>
</button>
1reaction
REJackcommented, Jan 26, 2017

Strange, i have not this issues with the icons. I had this before and then i switched the $('.box[data-name="'+box.boxname+'"]').find('.btn-box-tool[data-widget="collapse"... from the if’s (before i posted it here)

here my full code

  $($.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors.collapse).click(function () {
      var box = this.closest('.box');
      var boxname = $(box).data('name');
      if(boxname !== undefined){
          var boxstates = localStorage.box_state;
          if(!boxstates){
              boxstates = [];
          } else {
              boxstates = JSON.parse(boxstates);
          }
          boxstates = $.grep(boxstates, function(n) {
              return n.boxname != boxname;
          });
          boxstates.push({'boxname': boxname, 'state': $(box).hasClass('collapsed-box') ? 1 : 0});
          localStorage.box_state = JSON.stringify(boxstates);
      }
  });
  //load states
  var boxstates = localStorage.box_state;
  if(!boxstates){
      boxstates = [];
  } else {
      boxstates = JSON.parse(boxstates);
  }
  boxstates.forEach(function(box) {
      if(box.state == 0){
          $('.box[data-name="'+box.boxname+'"]').addClass('collapsed-box');
          $('.box[data-name="'+box.boxname+'"]').find('.btn-box-tool[data-widget="collapse"] i').removeClass('fa-minus').addClass('fa-plus');
      }else if(box.state == 1){
          $('.box[data-name="'+box.boxname+'"]').removeClass('collapsed-box');
          $('.box[data-name="'+box.boxname+'"]').find('.btn-box-tool[data-widget="collapse"] i').removeClass('fa-plus').addClass('fa-minus');
      }
  });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Open / Save as dialog boxes - choose whether to expand or ...
UPDATE: manually collapsed all then SHIFT-clicked the upper-right X to close the window. Reopened File Explorer, and all were collapsed.
Read more >
AdminLTE collapsed boxes by default - html - Stack Overflow
Ideally, what we'd want is to have the boxes be in the "slide up" state by default with the class "collapsed-box" so that...
Read more >
Starting Outlook with all folders collapsed/expanded
If a folder is collapsed and a new message is delivered to one of its subfolders, the folder will automatically expand to that...
Read more >
st.expander - Streamlit Docs
Insert a multi-element container that can be expanded/collapsed. ... If True, initializes the expander in "expanded" state. Defaults to False (collapsed).
Read more >
Collapse · Bootstrap v5.0
The collapse JavaScript plugin is used to show and hide content. ... element to be open by default using the show class, set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found