Remove sidebar · Issue #26 · start-angular/sb-admin-angular · GitHub
Skip to content

Remove sidebar #26

Open
Open

Description

@amolpatel

Is there any efficient way to remove the sidebar from a specific page? For example, for my charts.html file, I want to only display the top header but remove the sidebar completely. Is there any elegant solution to this?

Activity

  1. aryehbeitz commented on Dec 16, 2015

    @aryehbeitz

    I found a way:
    on header.html i change to
    <a class="navbar-brand" onclick="window.toggleNavbar()" style="cursor: pointer;">SB Admin 2</a>

    on sb-admin-2.js i add inside $(function() {

    window.showNavbar = true;
    window.toggleNavbar = function() {
        if (window.showNavbar) { //showing and want to hide
            $("#page-wrapper").css({"margin": "0"});
            $('div.navbar-collapse').addClass('collapse');
            $('#side-menu').hide();
        }
        else if (!window.showNavbar) {
            $("#page-wrapper").css({"margin": "0 0 0 250px"});
            $('div.navbar-collapse').removeClass('collapse');
            $('#side-menu').show();
        }
        window.showNavbar = !window.showNavbar;
    }
    

    `
    Then when clicking on the title, it toggles the side bar
    Enjoy :)

  2. garciaba commented on Feb 29, 2016

    @garciaba

    @aryehbeitz Nice solution, but now everytimes that you switch to another page, the sidebar collapses even if it was opened in the previos page. Any way to keep the state of the sidebar between views?

  3. aryehbeitz commented on Mar 20, 2016

    @aryehbeitz

    @garciaba
    Ok, I found a solution using the localStorage.

    In the sb-admin-2.js file, first remove the code above from inside the $(function() {.
    Then, add the following to the bottom of the file, outside any function:

    function hideNavbar() {
      $("#page-wrapper").css({"margin": "0"});
      $('div.navbar-collapse').addClass('collapse');
      $('#side-menu').hide();
    }
    function unhideNavbar() {
      $("#page-wrapper").css({"margin": "0 0 0 250px"});
      $('div.navbar-collapse').removeClass('collapse');
      $('#side-menu').show();
    }
    function toggleNavbar() {
        if (localStorage.showNavbar == 1) { //showing and want to hide
          hideNavbar();
        }
        else {
          unhideNavbar();
        }
        localStorage.showNavbar = (localStorage.showNavbar == 0)?1:0;
    }
    

    Now in the file sidebar.js, add to the body of the controller:

     if (localStorage.showNavbar === undefined) {
          localStorage.showNavbar = 1;
        }
        if (localStorage.showNavbar == 1) {
          unhideNavbar();
        } else {
          hideNavbar();
        }
    

    Leave the line in the header.html as:
    <a class="navbar-brand" onclick="window.toggleNavbar()" style="cursor: pointer;">SB Admin 2</a>

  4. kinho commented on Dec 21, 2016

    @kinho

    I'm using data-toggle="collapse" data-target=".navbar-collapse" in menu items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions