Module: Lipsiadmin::Controller::Ext

Defined in:
lib/controller/ext.rb

Defined Under Namespace

Classes: ColumnStore

Instance Method Summary collapse

Instance Method Details

#column_store_for(model, &block) ⇒ Object

Return column config, and store config/data for ExtJS ColumnModel and Store

Examples:

# app/controllers/backend/debtors_controller.rb
def index
  @column_store = column_store_for Debtor do |cm|
    cm.add :id
    cm.add "full_name_or_company.upcase",   "Full Name",      :sortable => true, :dataIndex => :company
    cm.add :surname  # Header will be autogenerated
    cm.add :email,                          "Email",          :sortable => true
    cm.add :piva,                           "Piva",           :sortable => true
    cm.add :created_at,                     "Creato il",      :sortable => true, :renderer => :date, :align => :right
    cm.add :updated_at,                     "Aggiornato il",  :sortable => true, :renderer => :datetime, :align => :right
  end

  respond_to do |format|
    format.js
    format.json do
      render :json => @column_store.store_data(params)

      # or you can manually do:
        # debtors           = Debtor.search(params)
        # debtors_count     = debtors.size
        # debtors_paginated = debtors.paginate(params)
        # render :json => { :results => @column_store.store_data_from(debtors_paginated), :count => debtors_count }
    end
  end
end

# app/views/backend/index.rjs
page.grid do |grid|
  grid.id "debtors-grid" # If you don't set this columns are not saved in cookies
  grid.title "List al debtors"
  grid.base_path "/backend/debtors"
  grid.forgery_protection_token request_forgery_protection_token
  grid.authenticity_token form_authenticity_token
  grid.tbar  :default
  grid.store do |store|
    store.url "/backend/debtors.json"
    store.fields @column_store.store_fields
  end
  grid.columns do |columns|
    columns.fields @column_store.column_fields
  end
  grid.bbar  :store => grid.get_store, :pageSize => params[:limit] # Remember to add after defining store!
end


52
53
54
# File 'lib/controller/ext.rb', line 52

def column_store_for(model, &block)
  ColumnStore.new(model, &block)
end