Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Includes:
- Gridify
- Defined in:
- lib/jquery/secret_sauce/model/find_for_grid.rb,
lib/jquery/gridify.rb
Class Method Summary collapse
-
.find_for_grid_2(params) ⇒ Object
takes params from request and returns records serialized to json.
Methods included from Gridify
Class Method Details
.find_for_grid_2(params) ⇒ Object
takes params from request and returns records serialized to json. handles the majority of the functionality for searching, sorting, and serializing records to be consumed by jqGrid.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jquery/secret_sauce/model/find_for_grid.rb', line 5 def self.find_for_grid_2(params) = {:limit => params["rows"]} [:offset] = (params["page"].to_i * params["rows"].to_i) - params["rows"].to_i [:order] = "#{params['sidx']} #{params['sord']}" if params["sidx"] != "" if params["_search"] == "true" string_search_operations = { "eq" => "=", "ne" => "<>", "bw" => "LIKE", "bn" => "NOT LIKE", "ew" => "LIKE", "en" => "NOT LIKE", "cn" => "LIKE", "nc" => "NOT LIKE" } integer_search_operations = { "eq" => "=", "ne" => "<>", "lt" => "<", "le" => "<=", "gt" => ">", "ge" => ">=" } if [:text, :string].include?(self.columns.select { |c| c.name == params["searchField"] }.first.type) && string_search_operations.keys.include?(params["searchOper"]) [:conditions] = "#{params["searchField"]} " [:conditions] << "#{string_search_operations[params["searchOper"]]}" [:conditions] << "'#{"%" if ["ew", "en", "cn", "nc"].include?(params["searchOper"])}#{params["searchString"]}#{"%" if ["nc", "cn", "bn", "bw"].include?(params["searchOper"])}'" elsif [:integer].include?(self.columns.select { |c| c.name == params["searchField"] }.first.type) && integer_search_operations.keys.include?(params["searchOper"]) [:conditions] = "#{params["searchField"]} #{integer_search_operations[params["searchOper"]]} #{params["searchString"]}" end end count = self.count(:all, :conditions => [:conditions]).to_f # raise count.inspect array = self.find(:all, ).collect { |r| r.attributes } {:total => (count / params["rows"].to_f).ceil, :page => params["page"], :records => count, :rows => array}.to_json end |