Module: DatatablesRails::Out

Defined in:
lib/datatables_rails.rb

Constant Summary collapse

CUSTOM_MAPPINGS =
{:process => "bProcessing", :jqueryui => "bJQueryUI", :paginate => "bPaginate",
                   :autowidth => "bAutoWidth", :defer_render => "bDeferRender",
                   :destroy => "bDestroy", :filter => "bFilter", :info => "bInfo", 
                   :length_change => "bLengthChange", :retrieve => "bRetrieve", 
                   :scroll_collapse => "bScrollCollapse", :scroll_infinite => "bScrollInfinite",
                   :searchable => "bSearchable", :server_side => "bServerSide", 
                   :sort => "bSort", :sortable => "bSortable", :sort_cells_top => "bSortCellsTop",
                   :sort_classes => "bSortClasses", :state_save => "bStateSave", 
                   :use_rendered => "bUseRendered", :visible => "bVisible"                           
}

Class Method Summary collapse

Class Method Details

.javascript(id, opts, source, cols) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/datatables_rails.rb', line 14

def javascript(id, opts, source, cols)
  dt_opts = []
  opts.each do |k,v|
    dt_opts << "'#{CUSTOM_MAPPINGS[k]}':true" if v
  end
  dt_opts << "'sAjaxSource': '#{source}'"
  columns = []
  cols.each do |col|
    columns << "{'mDataProp' : '#{col}'}"
  end
  dt_opts << "'aoColumns': [ #{columns.join(',')} ]"
 
  html = []
  html << "<script>"
  html << "$(document).ready(function()  { "
  html << "var #{id}_o = $('##{id}').dataTable( { #{dt_opts.join(',')} } );"
  html << "});"
  html << "</script>"
  return html.join
end