Class: DataTables::Modules::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/data_tables/modules/pagination.rb

Constant Summary collapse

FIRST_PAGE =
'0'
DEFAULT_LENGTH =
'10'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/data_tables/modules/pagination.rb', line 9

def context
  @context
end

#scopeObject (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

#paginateObject



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