Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to load a multiple contextmenu? #5

Closed
ibakayoko opened this issue Nov 13, 2015 · 6 comments
Closed

Is it possible to load a multiple contextmenu? #5

ibakayoko opened this issue Nov 13, 2015 · 6 comments

Comments

@ibakayoko
Copy link

Hello,

Thank you for the nice plugin.
I have a table that displays items of different types { folders and files }.
I want to have different contextMenu for each type.

Is it possible to do that with the plugin?

@prograhammer
Copy link
Owner

Ah, ok, I had thought once that someone might need that. Let me see this weekend...

@ibakayoko
Copy link
Author

Thank you

On Saturday, November 14, 2015, David Graham notifications@github.com
wrote:

Ah, ok, I had thought once that someone might need that. Let me see this
weekend...


Reply to this email directly or view it on GitHub
#5 (comment)
.

@prograhammer
Copy link
Owner

Hi, @ibakayoko

See this fiddle: http://jsfiddle.net/t3a9ug81/1/
Notice in this fiddle that each button shows a different context menu. Also notice that right-clicking row 3 and right-clicking row 4 also bring up different context menus.

I added an option called beforeContextMenuRow that will allow you to more programmatically show the context menu. Set it to a function and in your function use the method showContextMenu like $('#table').bootstrapTable('showContextMenu',{event:e, ... }); to show the context menu you want. Just make sure to return false to prevent the default context menu behavior from happening afterwards. I'll update the documentation/demo tomorrow, but refer to the fiddle above for now. Feel free to ask me any more questions for clarification.

@ibakayoko
Copy link
Author

I will checkout the latest code and try to implement on my project.

I will report the result of my integration.

Thank you very much

On Fri, Nov 20, 2015 at 4:10 AM, David Graham notifications@github.com
wrote:

Hi, @ibakayoko https://github.com/ibakayoko

See this fiddle: http://jsfiddle.net/t3a9ug81/1/

I added an option called beforeContextMenuRow that will allow you to more
programmatically show the context menu. Set it to a function and use it
(along with $('#table').bootstrapTable('showContextMenu',{event:e, ... });)
to setup the context menu how you want. Just make sure to return false to
prevent the default context menu behavior. I'll update the
documentation/demo in a few days.


Reply to this email directly or view it on GitHub
#5 (comment)
.

@ibakayoko
Copy link
Author

Works very well.

 var $table = $('#grid');

      $table.bootstrapTable({
            //contextMenu: '#folders-menu',
            beforeContextMenuRow: function(e, row, b){  
                 if(row.type == 'folders'){
                        $table.bootstrapTable('showContextMenu',{event:e, contextMenu:'#folders-menu'});
                    }
                    else if(row.type == 'files'){
                        $table.bootstrapTable('showContextMenu',{event:e, contextMenu:'#files-menu'});
                    }  

                 return false;

            },          
            onContextMenuItem: function(row, $el){
                if($el.data("item") == "edit"){
                    alert("Edit: " + row.type + ' ' + row.name + ' ' + row.modified_at);
                } else if($el.data("item") == "delete"){
                    alert("Delete: " + row.type + ' ' + row.name + ' ' + row.modified_at);
                } else if($el.data("item") == "action1"){
                    alert("Action1: " + row.type + ' ' + row.name + ' ' + row.modified_at);
                } else if($el.data("item") == "action2"){
                    alert("Action2: " + row.type + ' ' + row.name + ' ' + row.modified_at);
                }
            }
        });

@prograhammer
Copy link
Owner

Yeah I think that looks great. And you can have conditions in your onContextMenuItem like

 if ($el.data("item") == "edit" && row.type == "folders")  {
      // edit folders
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants