Giter Site home page Giter Site logo

Adding items to menu about metismenu HOT 15 OPEN

onokumus avatar onokumus commented on July 21, 2024
Adding items to menu

from metismenu.

Comments (15)

sferoze avatar sferoze commented on July 21, 2024 1

I got it I had to change the code to:

var sideMenu = $(this.sideMenuContainer);
sideMenu.removeData("mm");
sideMenu.metisMenu();

from metismenu.

garhbod avatar garhbod commented on July 21, 2024 1

For angularJs I had to add a timeout to wait for the dom change before running metisMenu again

            // After changes to dom
            $timeout(function() {
                var sideMenu = angular.element('[side-navigation]');
                sideMenu.removeData("mm");
                sideMenu.metisMenu();
            });

from metismenu.

juristr avatar juristr commented on July 21, 2024

Yep, same problem here with my Angular app. Any way to circumvent this, otherwise I have to digg into the codebase :)

from metismenu.

juristr avatar juristr commented on July 21, 2024

Ok, just had a quick look on the codebase

    $.fn[ pluginName ] = function (options) {
        return this.each(function () {
            if (!$.data(this, "plugin_" + pluginName)) {
                $.data(this, "plugin_" + pluginName, new Plugin(this, options));
            }
        });
    };

As can be seen the plugin remembers whether it has been already initialized. The line if (!$.data(this, "plugin_" + pluginName)) { is the "culprit". Commenting the if and consequently re-calling $(...).metisMenu() seems to work.

Now there are different possibilities.

  • simply removing the if clause
  • adding a refresh function...like $(...).metisMenu('refresh') or similar...

Any input from the author would be author @onokumus would be cool, I'm also willing to submit a pull request with the fix. πŸ˜„

from metismenu.

David-Melo avatar David-Melo commented on July 21, 2024

I have noticed that just re-calling $(element).metisMenu(); after adding the items will give the expected results. I have been using this without modifying any of the codebase. However, I'm not sure how this affects any registered events.

from metismenu.

juristr avatar juristr commented on July 21, 2024

That's kinda strange as according to the codebase this shouldn't be possible (if I'm not missing something). Are you sure you're using the latest version? Maybe in a previous one the plugin simply didn't have the if clause.

from metismenu.

David-Melo avatar David-Melo commented on July 21, 2024

Agreed it is strange, a refresh method would be nice. I'm using the latest v1.1.1 using the method I mentioned but a neater way to do it would be great.

from metismenu.

thomasvanlankveld avatar thomasvanlankveld commented on July 21, 2024

I got around this problem by using jQuery's removeData()

var sideMenu = $(this.sideMenuContainer);
sideMenu.removeData("plugin_metisMenu");
sideMenu.metisMenu();

from metismenu.

arlen43 avatar arlen43 commented on July 21, 2024

This problem is caused by it need init again when the dom is changed. Just add one line code to init will be ok.

$.fn[ pluginName ] = function (options) {
    return this.each(function () {
        if (!$.data(this, "plugin_" + pluginName)) {
            $.data(this, "plugin_" + pluginName, new Plugin(this, options));
        } 
        // add this case
        else {
            $.data(this, "plugin_" + pluginName).init();
        }
    });
};

And when you changed dom anywhere, the only thing you need to do is call the following code

$(selector).metisMenu();

from metismenu.

dbilovd avatar dbilovd commented on July 21, 2024

Thanks @thomasvanlankveld that worked for me. Haven't tried @arlen43 's solution.

from metismenu.

rosesonfire avatar rosesonfire commented on July 21, 2024

thanks @arlen43 ! your solution worked for me.

from metismenu.

sferoze avatar sferoze commented on July 21, 2024

Although it doesnt really work that well. I notice that the the navigation dropdown always stays open. And doesn't close. At least one stays open. When I refresh the page it works. We really need to find a way to reload the menu

from metismenu.

sferoze avatar sferoze commented on July 21, 2024

Ok so actually I figured out how to use @arlen43 solution but with the newest MetisMenu code

  function Plugin(option) {
    return this.each(function() {
      var $this = $(this);
      var data = $this.data('mm');
      var options = $.extend({},
        MetisMenu.DEFAULTS,
        $this.data(),
        typeof option === 'object' && option
      );

      if (!data) {
        $this.data('mm', (data = new MetisMenu(this, options)));
      } else {
        $this.data('mm').init();
      }
      if (typeof option === 'string') {
        data[option]();
      }
    });
  }

Now things reload like normal

from metismenu.

salvadoresc avatar salvadoresc commented on July 21, 2024

this worked for me:

var sideMenu = $('#leftMenu');
sideMenu.removeData("mm");
sideMenu.metisMenu();

but, now, when i open a menu, im not able to close it unless i open another, so i always have an open menu.

from metismenu.

onokumus avatar onokumus commented on July 21, 2024

See #116

from metismenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.