Class: DataTables::Modules::Pagination
- Inherits:
-
Object
- Object
- DataTables::Modules::Pagination
- Defined in:
- lib/data_tables/modules/pagination.rb
Constant Summary collapse
- FIRST_PAGE =
'0'- DEFAULT_LENGTH =
'10'
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(model, scope, params) ⇒ Pagination
constructor
A new instance of Pagination.
- #paginate ⇒ Object
Constructor Details
#initialize(model, scope, params) ⇒ Pagination
Returns a new instance of Pagination.
11 12 13 14 15 |
# File 'lib/data_tables/modules/pagination.rb', line 11 def initialize(model, scope, params) @scope = scope.dup @model = model @params = params end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/data_tables/modules/pagination.rb', line 9 def context @context end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
9 10 11 |
# File 'lib/data_tables/modules/pagination.rb', line 9 def scope @scope end |
Instance Method Details
#paginate ⇒ Object
17 18 19 20 21 22 |
# File 'lib/data_tables/modules/pagination.rb', line 17 def paginate start = (@params[:start] || FIRST_PAGE).to_i length = (@params[:length] || DEFAULT_LENGTH).to_i page = (start / length) @scope.offset(page * length).limit(length) end |