class TradesDatatable

Public Instance Methods

as_json(options = {}) click to toggle source

This will return all the data that DataTables expects including all the relevant rows from the database.

# File app/datatables/trades_datatable.rb, line 6
def as_json(options = {})
  conditions = if params[:sSearch].present?
    ["LOWER(name) LIKE :q", q: "%#{params[:sSearch].downcase}%"]
  else
    {}
  end
  as_datatable(Trade.includes(:subtrades), conditions)
end
data_hash(trade) click to toggle source

This fetches the correct page of data in the correct order.

# File app/datatables/trades_datatable.rb, line 16
def data_hash(trade)
  {
    id: trade.id,
    name: link_to(trade.name, admin_trade_subtrades_path(trade)),
    description: trade.description,
    sub_trades: link_to(trade.subtrades_count, admin_trade_subtrades_path(trade)),
    action: admin_action_link(trade)
  }
end
sort_columns() click to toggle source

Provide the sequence in which columns to be sorted.

# File app/datatables/trades_datatable.rb, line 27
def sort_columns
  ['name', 'description', 'subtrades_count']
end