Module: JqgridJson

Includes:
ActionView::Helpers::JavaScriptHelper, HandleAttributes
Included in:
Array
Defined in:
lib/jquery/jqgrid/jqgrid.rb,
lib/jquery/gridify/grid_view.rb

Instance Method Summary collapse

Methods included from ActionView::Helpers::JavaScriptHelper

#javascript_function, #jquery_id, #jquery_ids

Instance Method Details

#to_jqgrid_json(attributes, current_page, per_page, total) ⇒ Object



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/jquery/jqgrid/jqgrid.rb', line 425

def to_jqgrid_json(attributes, current_page, per_page, total)
  json = %Q({"page":"#{current_page}","total":#{total/per_page.to_i+1},"records":"#{total}")
  if total > 0
    json << %Q(,"rows":[)
    each do |elem|
      elem.id ||= index(elem)
      json << %Q({"id":"#{elem.id}","cell":[)
      couples = elem.attributes.symbolize_keys
      attributes.each do |atr|
        value = get_atr_value(elem, atr, couples)
        value = escape_javascript(value) if value and value.is_a? String
        json << %Q("#{value}",)
      end
      json.chop! << "]},"
    end
    json.chop! << "]}"
  else
    json << "}"
  end
end

#to_subgrid_json(attributes) ⇒ Object



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/jquery/gridify/grid_view.rb', line 422

def to_subgrid_json(attributes)
  json = %Q({)
  if self.empty?
    json << "}"
  else
    json <<= %Q("rows":[)
    each do |elem|
      elem.id ||= index(elem)
      json << %Q({"id":"#{elem.id}","cell":[)
      couples = elem.attributes.symbolize_keys
      attributes.each do |atr|
        value = get_atr_value(elem, atr, couples)
        value = escape_javascript(value) if value and value.is_a? String
        json << %Q("#{value}",)
      end
      json.chop! << "]},"
    end
    json.chop! << "]}"
  end
end