EasyUI Forum
May 16, 2024, 04:43:50 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: how do you add a menu separator programmtically via appendItem?  (Read 17031 times)
jpierce
Jr. Member
**
Posts: 73


View Profile
« on: September 04, 2013, 02:36:25 PM »

I know how to use menu-sep to add separators to menus at design-time, but how do you do that using appendItem?  I've tried everything I can think of.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 05, 2013, 01:19:20 AM »

To append a menu separator, please download the updated menu plugin from http://www.jeasyui.com/easyui/plugins/jquery.menu.js and include it in your page.
Code:
$('#mm').menu('appendItem', {separator:true});
Logged
jpierce
Jr. Member
**
Posts: 73


View Profile
« Reply #2 on: September 05, 2013, 09:40:49 AM »

That did the trick.  Thanks for the quick turnaround!

Will you be integrating that into a future version?
Logged
jpierce
Jr. Member
**
Posts: 73


View Profile
« Reply #3 on: October 01, 2013, 12:56:40 PM »

Okay, now I've run into another difficulty.  How am I supposed to remove the dynamically added separator?  I wind up regenerating this menu often and have all these lines building up.  I can't figure out any way to get the seps with findItem in order to remove them.

There should be a way to do that, but to be honest a 'clear' method would be more useful for my present needs.

Also, can you send me these replacement jquery.menu.js files (or a link to them) in non-obfuscated format since I am a paid commercial subscriber?  It's great to have to obfuscated ones here for everyone to use, but it'd help me figure out/solve some of my own problems as well as provide you with better bug reporting if I had the non-obfuscated ones.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: October 01, 2013, 03:16:21 PM »

Hi jpierce,

The 'removeItem' method can be used to remove menu item including the separator line.
Code:
var m = $('#mm');
m.menu('appendItem', {id:'s1',separator:true});  // append item separator line
m.menu('removeItem', $('#s1')[0]);  // remove it

Also, the updated menu plugin has been sent to you by email.
Logged
jpierce
Jr. Member
**
Posts: 73


View Profile
« Reply #5 on: October 01, 2013, 03:36:17 PM »

Thanks, that worked, though it's a bit clunky to have to do it that way in my code.

I'd just like to plug again my request for a 'clear'.  Otherwise, here's what I'm having to do:

Code:
            $('.menu-text', menuElem)
                    .map(function (i, e) {
                        return e.textContent
                    })
                    .each(function (i, e) {
                        menuElem.menu('removeItem', menuElem.menu('findItem', e).target)
                    });

            if ($('#' + item.id + '_separator').length === 1) {
                menuElem.menu('removeItem', $('#' + item.id + '_separator')[0]);
            }

It's complicated by the fact that I have to do this for several menus (I have a sequence of "Presets" dropdown buttons for various fields).  It's just extra gross.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #6 on: October 01, 2013, 06:30:08 PM »

The 'clear' method can be extended as below.
Code:
$.extend($.fn.menu.methods,{
clear: function(jq){
return jq.each(function(){
var m = $(this);
m.children('div.menu-item,div.menu-sep').each(function(){
m.menu('removeItem',this);
});
});
}
});
Logged
jpierce
Jr. Member
**
Posts: 73


View Profile
« Reply #7 on: October 03, 2013, 08:52:01 AM »

Works great, thanks!
Logged
iceh
Jr. Member
**
Posts: 61


View Profile
« Reply #8 on: November 14, 2013, 11:41:22 AM »

Any timeframe when this will make it in 1.3.5?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!