Module: JqGridRails::View

Includes:
ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::TagHelper, Helpers
Defined in:
lib/jqgrid_rails/jqgrid_rails_view.rb

Instance Method Summary collapse

Methods included from Helpers

#build_default_callback, #build_selection_callback, #build_single_callback, #build_toolbar_button, #confirm_if_required, #convert_dom_id, #csrf_token_discovery, #extract_callback_variables, #hash_to_callback, #map_click, #scrub_options_hash, #selection_array

Instance Method Details

#jq_grid(grid) ⇒ Object Also known as: jqgrid

grid

JqGrid Object

Returns complete jqGrid instructions for building within HTML document



31
32
33
34
35
36
37
38
# File 'lib/jqgrid_rails/jqgrid_rails_view.rb', line 31

def jq_grid(grid)
  output = jqgrid_html(grid)
  output << jqgrid_js(grid)
  if grid.detached_javascript.present?
    output << javascript_tag{ "jQuery(document).ready(function(){ #{grid.detached_javascript.join("\n")}});".html_safe }
  end
  output.html_safe
end

#jqgrid_addrow(dom_id, idx, row_hash) ⇒ Object



41
42
43
# File 'lib/jqgrid_rails/jqgrid_rails_view.rb', line 41

def jqgrid_addrow(dom_id, idx, row_hash)
  "jQuery(#{convert_dom_id(dom_id)}).add_row(#{format_type_to_js(idx)}, #{format_type_to_js(row_hash)});".html_safe
end

#jqgrid_html(grid_or_id, *args) ⇒ Object

grid_or_id

JqGrid Object or ID

Returns required HTML for grid



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jqgrid_rails/jqgrid_rails_view.rb', line 11

def jqgrid_html(grid_or_id, *args)
  dom_id = grid_or_id.respond_to?(:table_id) ? grid_or_id.table_id : grid_or_id
  output = "<div id=\"#{dom_id}_holder\" style=\"width:100%\"><table id=\"#{dom_id}\" width=\"100%\"></table></div>"
  if((grid_or_id.respond_to?(:has_link_toolbar?) && grid_or_id.has_link_toolbar?) || args.include?(:with_link_toolbar))
    output << "<div id=\"#{dom_id}_linkbar\" class=\"jqgrid_linkbar\"></div>"
  end
  if((grid_or_id.respond_to?(:has_pager?) && grid_or_id.has_pager?) || args.include?(:with_pager))
    output << "<div id=\"#{dom_id}_pager\"></div>"
  end
  output.html_safe
end

#jqgrid_js(grid, *args) ⇒ Object

grid

JqGrid Object

Returns required javascript for grid



25
26
27
# File 'lib/jqgrid_rails/jqgrid_rails_view.rb', line 25

def jqgrid_js(grid, *args)
  args.include?(:notag) || args.include?(:raw) ? grid.build : javascript_tag(grid.build)
end

#reload_grid(dom_id, *args) ⇒ Object

dom_id

Grid DOM ID

args

Extra arguments. :raw for no tag wrapping

Reload given table



62
63
64
65
66
67
68
69
70
# File 'lib/jqgrid_rails/jqgrid_rails_view.rb', line 62

def reload_grid(dom_id, *args)
  dom_id = "##{dom_id}" unless dom_id.start_with?('#')
  output = "jQuery('#{dom_id}').trigger('reloadGrid');".html_safe
  if(args.include?(:wrapped))
    javascript_tag(output)
  else 
    output
  end
end

#table_to_grid(dom_id, options = {}) ⇒ Object

dom_id

DOM ID of existing table

options

Options hash for jqgrid



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jqgrid_rails/jqgrid_rails_view.rb', line 47

def table_to_grid(dom_id, options={})
  [:ondbl_click_row,:on_cell_select].each do |key|
    map_click(key, options)
  end
  options.each do |key,val|
    if(val.is_a?(Hash))
      options[key] = hash_to_callback(val)
    end
  end
  javascript_tag("tableToGrid(#{convert_dom_id(dom_id)}, #{format_type_to_js(options)}); jQuery(#{convert_dom_id(dom_id)}).trigger('reloadGrid');")
end