Class: DataTables::Modules::Pagination

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

Constant Summary collapse

FIRST_PAGE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_scope, filtered_scope, request_parameters) ⇒ Pagination

Returns a new instance of Pagination.



10
11
12
13
14
# File 'lib/data_tables/modules/pagination.rb', line 10

def initialize(original_scope, filtered_scope, request_parameters)
  @original_scope = original_scope
  @filtered_scope = filtered_scope
  @request_parameters = request_parameters
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#filtered_scopeObject (readonly)

Returns the value of attribute filtered_scope.



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

def filtered_scope
  @filtered_scope
end

#original_scopeObject (readonly)

Returns the value of attribute original_scope.



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

def original_scope
  @original_scope
end

Instance Method Details

#paginateObject



16
17
18
19
20
21
# File 'lib/data_tables/modules/pagination.rb', line 16

def paginate
  start = (@request_parameters[:start] || '0').to_i
  length = (@request_parameters[:length] || '10').to_i
  page = (start / length)
  @filtered_scope = @filtered_scope.offset(page * length).limit(length)
end