class Gridify::GridColumn

Attributes

align[RW]
ar_column[RW]
edit_options[RW]
editable[RW]
fixed_width[RW]
form_options[RW]
hidden[RW]
key[RW]
label[RW]
name[RW]
resizable[RW]
searchable[RW]
sortable[RW]
validations[RW]
value_type[RW]
width[RW]

Public Class Methods

new(options) click to toggle source
# File lib/gridify/grid_column.rb, line 35
def initialize(options)
  update options
end

Public Instance Methods

properties() click to toggle source
# File lib/gridify/grid_column.rb, line 47
def properties
  jqgrid_properties
end
to_json() click to toggle source
# File lib/gridify/grid_column.rb, line 43
def to_json
  properties.to_json #_with_js
end
update(options) click to toggle source
# File lib/gridify/grid_column.rb, line 39
def update(options)
  options.each {|atr, val| send( "#{atr}=", val )}
end

Private Instance Methods

jqgrid_properties() click to toggle source

note, we dont vals = foo because dont want to bother generating key if its same as jqGrid default

# File lib/gridify/grid_column.rb, line 86
def jqgrid_properties
  vals = {
    :name           => name,
    :index          => name
  }
  #xmlmap not required when same as :name
  # vals[:xmlmap]     = name          if data_type == :xml
  # vals[:jsonmap]    = name          if data_type == :json
  
  vals[:label]      = label || name.titleize
  vals[:resizable]  = false         if resizable==false
  vals[:fixed]      = fixed_width   unless fixed_width==false
  vals[:sortable]   = false         if sortable==false
  vals[:sorttype]   = jqgrid_type   if sortable 
  vals[:search]     = false         if searchable==false  
  vals[:editable]   = true          if editable
  vals[:align]      = 'right'       if [:integer, :float, :currency].include?(value_type)
  case value_type
  when :datetime
    vals[:formatter] = 'date'
    vals[:formatoptions] = { :srcformat => 'UniversalSortableDateTime', :newformat => 'FullDateTime' }
  end
  vals[:hidden]     = true          if hidden
  vals[:width]      = width         if width
  vals[:editoptions] = edit_options if editable && edit_options
  vals[:editrules]  = validations   if editable && validations
    # and more...
    
  vals
end
jqgrid_type() click to toggle source

# File lib/gridify/grid_column.rb, line 73
def jqgrid_type
  return sortable unless sortable==true
  case value_type
  when :string   then 'text'
  when :text     then 'text'
  when :integer  then 'integer'
  when :float    then 'float'
  when :boolean  then 'boolean'
  when :datetime then 'date'
  end
end