How to remember the toggle state of the sidebar menu?
See original GitHub issueI am using AdminLTE in combination with Codeigniter3. Therefore a lot of HTML is generated on the back-end of my application. I’d like to find a way to let the back-end know the toggle state (collapsed or open) of the sidebar menu so that I can generate the appropriate HTML for a page.
I tried to use the href in:
<a href="<?= site_url("site/toggle");?>" class="sidebar-toggle" data-toggle="offcanvas" role="button">
but that doesn’t work because the href is not used.
Does anyone know a way to achieve this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:24
Top Results From Across the Web
How to remember the toggle state of the sidebar in AdminLTE3?
Adminlte3. Just simple add data-enable-remember="true" to your "pushmenu" button. Example code: <a class="nav-link" data-widget="pushmenu" ...
Read more >Keep menu toggle state after page reload | Jin's blog
We need to store this state into localStorage and re-set it when page is reloaded.
Read more >Toggle Sidebar Navigation HTML CSS Javascript - YouTube
Toggle Sidebar Navigation HTML CSS Javascript-------------------------------------------------------------------------Cheapest Domain ...
Read more >how to remember the toggle state of the sidebar menu
Click on the toggle menu you will see a sidebar navigation slides out from the left side of the screen while pushing the...
Read more >Sidebar, UI Widgets Webix Docs
The Menu button allows collapsing the menu items into a vertical navigation bar with icons. In this state menu items will be shown...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, do not use cookies. It’s easier to use LocalStorage. I did it here.
This works perfectly for me.
Thanks.
Thanks @REJack for your script, works nicely!
I adapted it slightly so it uses localStorage. One of the advantages of this approach is that it remembers the state for all pages, whereas the cookie would be set per path. Basically this means the toggle state was remembered on a per page basis (at least in my browser, Chrome 61 on Windows 10), which may be ideal for some uses cases but not mine.
I also tried to reproduce the bug @kher09 mentioned, without much luck. Maybe someone else can chip in there.