Adminlte: Save menu state (collapse/uncollapse)

Created on 22 Apr 2016  路  2Comments  路  Source: ColorlibHQ/AdminLTE

Hi, guys
When I turn the menu to collapse state and go to an other page the menu turn back to previous state. How do you save the menu state? Maybe cookies?
Many thanks for your answers!

Most helpful comment

A pure javascript / frontend solution was not possible for me.
You got to send the right class ('sidebar-collapse') right on pageload, if the sidebar should be collapsed.

Like (Laravel Blade):
@if(session('sidebar-collapse', '0') == 1) sidebar-collapse @endif

And then bind the the click on .sidebar-toggle to some event that triggers a request:

    $('.sidebar-toggle').click(function() {
        if($('body').delay(300).hasClass('sidebar-collapse')) {
            $.get('/sidebar/collapse');
        }
        else {
            $.get('/sidebar/decollapse');
        }
    });

The corresponding site saves the sidebar-collapse var into the session.

Hope i could help a bit.

All 2 comments

A pure javascript / frontend solution was not possible for me.
You got to send the right class ('sidebar-collapse') right on pageload, if the sidebar should be collapsed.

Like (Laravel Blade):
@if(session('sidebar-collapse', '0') == 1) sidebar-collapse @endif

And then bind the the click on .sidebar-toggle to some event that triggers a request:

    $('.sidebar-toggle').click(function() {
        if($('body').delay(300).hasClass('sidebar-collapse')) {
            $.get('/sidebar/collapse');
        }
        else {
            $.get('/sidebar/decollapse');
        }
    });

The corresponding site saves the sidebar-collapse var into the session.

Hope i could help a bit.

Due to some neglect in my part, many issues weren't addressed for some time. Some of these issues are no longer relevant since a solution might have been found. Therefore, we decided to close all issues that are over a month old. However, if the issue still persists and you'd like help, then by all means repost your issue and we will consider it again. In the mean time, we will close this post.

Thanks for your understanding and we apologize for any inconvenience <3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaea44 picture gaea44  路  3Comments

jrandhawa09 picture jrandhawa09  路  3Comments

REJack picture REJack  路  3Comments

jrlooney picture jrlooney  路  3Comments

acacha picture acacha  路  4Comments