Module: RailsJqGrid::ActsAsJqGridAble::InstanceMethods
- Defined in:
- lib/rails_jq_grid/acts_as_jq_grid_able.rb
Instance Method Summary collapse
-
#current_offset(default_recs_per_page = 10) ⇒ Object
calculates the current offset by page and records per page.
-
#current_page ⇒ Object
returns the current page retrieved from jqgrid request default 1.
-
#jqgrid_json(options) ⇒ Object
- creates json string for jqGrid options
-
:total_records count records totaly to display in grid, default :data.count :default_records_per_page when nothing is specified how many records are shown on a page, default :data.count :data the records as an array.
-
#order_by ⇒ Object
tests jqgrid request parameter sidx and sord and returns a sanatized order by statement.
-
#records_per_page(default_recs_per_page = 10) ⇒ Object
returns records per page retrieved from jqgrid request default 1.
Instance Method Details
#current_offset(default_recs_per_page = 10) ⇒ Object
calculates the current offset by page and records per page
62 63 64 |
# File 'lib/rails_jq_grid/acts_as_jq_grid_able.rb', line 62 def current_offset(default_recs_per_page = 10) (current_page - 1) * records_per_page(default_recs_per_page) end |
#current_page ⇒ Object
returns the current page retrieved from jqgrid request default 1
68 69 70 |
# File 'lib/rails_jq_grid/acts_as_jq_grid_able.rb', line 68 def current_page (params[:page] || 1).to_i end |
#jqgrid_json(options) ⇒ Object
creates json string for jqGrid
- options
-
:total_records count records totaly to display in grid, default :data.count :default_records_per_page when nothing is specified how many
records are shown on a page, default :data.count
:data the records as an array
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_jq_grid/acts_as_jq_grid_able.rb', line 48 def jqgrid_json() [:total_records] ||= [:data].count [:default_records_per_page] ||= [:data].count records_pp = records_per_page([:default_records_per_page]) total_pages = ([:total_records] + records_pp - 1).div(records_pp) json_data = {:currentpage => current_page , :totalpages => total_pages , :totalrecords => [:total_records]} json_data[:data] = [:data] json_data.to_json end |
#order_by ⇒ Object
tests jqgrid request parameter sidx and sord and returns a sanatized order by statement
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rails_jq_grid/acts_as_jq_grid_able.rb', line 80 def order_by order_column = params[:sidx] || "" unless allowed_order_by_cols.include?(order_column) order_column = self.class.allowed_order_by_cols.first || "" end order_column = order_column.to_s order = ["asc", "desc"].include?(params[:sord]) ? params[:sord] : "" if order_column.blank? "" else "#{order_column} #{order}" end end |
#records_per_page(default_recs_per_page = 10) ⇒ Object
returns records per page retrieved from jqgrid request default 1
74 75 76 |
# File 'lib/rails_jq_grid/acts_as_jq_grid_able.rb', line 74 def records_per_page(default_recs_per_page = 10) (params[:rows] || default_recs_per_page).to_i end |