module Daru::View::JsHelpers
Public Instance Methods
draw_ajax_option()
click to toggle source
@return [void] adds serverSide and ajax options
# File lib/daru/data_tables/generate_js/generate_js.rb, line 55 def draw_ajax_option ajax_str = '' ajax_str << "\nfunction ( data, callback, settings ) {" ajax_str << "\n\tvar out = [];" ajax_str << "\n\tfor (var i=data.start; i<data.start+data.length; i++) {" ajax_str << "\n\t\tif (i < data_array.length) {" ajax_str << "\n\t\t\tout.push( data_array[i] );" ajax_str << "\n\t\t}" ajax_str << "\n\t}" ajax_str << "\n\tsetTimeout( function () {" ajax_str << set_callback_ajax ajax_str << "\n\t}, 50 );" ajax_str << "\n}" @options[:serverSide] = true @options[:ajax] = ajax_str.js_code end
draw_js(element_id)
click to toggle source
@param id [String] The ID of the DIV element that the DataTable
should be rendered in
@return [String] Generates JavaScript function for rendering the Table.
# File lib/daru/data_tables/generate_js/generate_js.rb, line 12 def draw_js(element_id) if options[:data] && options[:data].length >= 50_000 data_array = extract_data_array draw_ajax_option end js = '' js << "\n$(document).ready(function() {" js << "\n" js << "\n\tvar data_array = #{data_array};" unless options[:data] js << "\n\t$('##{element_id}').DataTable(" js << "\n\t\t#{js_parameters(@options)}" js << "\n\t);" js << "\n" js << "\n});" js end
draw_js_iruby(element_id)
click to toggle source
@param id [String] The ID of the DIV element that the DataTable
should be rendered in
@return [String] Generates JavaScript function for rendering the Table
in IRuby notebook
# File lib/daru/data_tables/generate_js/generate_js.rb, line 33 def draw_js_iruby(element_id) if options[:data] && options[:data].length >= 50_000 data_array = extract_data_array draw_ajax_option end js = '' js << "\n$( function () {" js << "\n\tvar data_array = #{data_array};" unless options[:data] js << "\n\tvar table = $('##{element_id}').DataTable(" js << "\n\t\t#{js_parameters(@options)}" js << "\n\t);" js << "\n" js << "\n});" js end
extract_data_array()
click to toggle source
@return [Array, void] returns data Array if present in the options
# File lib/daru/data_tables/generate_js/generate_js.rb, line 50 def extract_data_array options.delete(:data) unless options[:data].nil? end
set_callback_ajax()
click to toggle source
@return [String] returns the callback js from the server
# File lib/daru/data_tables/generate_js/generate_js.rb, line 73 def set_callback_ajax callback_js = '' callback_js << "\n\t\tcallback( {" callback_js << "\n\t\t\tdraw: data.draw," callback_js << "\n\t\t\tdata: out," callback_js << "\n\t\t\trecordsTotal: data_array.length," callback_js << "\n\t\t\trecordsFiltered: data_array.length," callback_js << "\n\t\t} );" callback_js end