Permalink
Browse files

Add context menu support

  • Loading branch information...
1 parent 087cdd6 commit 81ade2f8dcc0329cc68b24405d93282485776741 @springbok springbok committed Dec 15, 2010
Showing with 19 additions and 3 deletions.
  1. +18 −3 lib/2dc_jqgrid.rb
  2. +1 −0 public/javascripts/jquery.contextmenu.r2.packed.js
View
@@ -12,7 +12,7 @@ def jqgrid_javascripts
js << javascript_include_tag('jqgrid/jquery.jqGrid.min.js') + "\n"
# Don't know if we need it, if smth not working, just uncomment it
#js << javascript_include_tag('jqgrid/grid.tbltogrid') + "\n"
- # js << javascript_include_tag('jqgrid/jquery.contextmenu.js') + "\n"
+ js << javascript_include_tag('jqgrid/jquery.contextmenu.r2.packed.js') + "\n"
end
def jqgrid(title, id, action, columns = [], options = {})
@@ -41,12 +41,13 @@ def jqgrid(title, id, action, columns = [], options = {})
:hiddengrid => 'false',
:hidegrid => 'false',
:shrinkToFit => 'true',
- :form_width => 300
+ :form_width => 300,
+ :context_menu => {:menu_handler => nil, :menu_bindings => nil, :menu_id => nil}
}.merge(options)
# Stringify options values
options.inject({}) do |options, (key, value)|
- options[key] = (key != :subgrid) ? value.to_s : value
+ options[key] = (key != :subgrid && key != :context_menu) ? value.to_s : value
options
end
@@ -176,6 +177,19 @@ def jqgrid(title, id, action, columns = [], options = {})
},/
end
+ # Context menu
+ # See http://www.trendskitchens.co.nz/jquery/contextmenu/
+ # http://www.hard-bit.net/files/jqGrid-3.5/ContextMenu.html
+ # http://www.hard-bit.net/blog/?p=171
+ #
+ context_menu = ""
+ if options[:context_menu].size > 0 && !options[:context_menu][:menu_handler].blank?
+ context_menu = %Q/
+ onRightClickRow: function(rowid,irow,icol,e){
+ $('#' + rowid).contextMenu('#{options[:context_menu][:menu_id]}', #{options[:context_menu][:menu_bindings]});
+ },/
+ end
+
# Enable subgrids
subgrid = ""
subgrid_enabled = "subGrid:false,"
@@ -305,6 +319,7 @@ def jqgrid(title, id, action, columns = [], options = {})
#{grid_loaded}
#{direct_link}
#{editable}
+ #{context_menu}
#{subgrid_enabled}
#{subgrid}
caption: "#{title}"

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 81ade2f

Please sign in to comment.