Class: ActiveDataTables::DataTablesResult

Inherits:
Object
  • Object
show all
Defined in:
lib/active_data_tables/active_data_tables.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(draw, data, records_total, records_filtered) ⇒ DataTablesResult

Returns a new instance of DataTablesResult.



31
32
33
34
35
36
# File 'lib/active_data_tables/active_data_tables.rb', line 31

def initialize(draw, data, records_total, records_filtered)
  @draw = draw
  @data = data
  @records_total = records_total
  @records_filtered = records_filtered
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



29
30
31
# File 'lib/active_data_tables/active_data_tables.rb', line 29

def data
  @data
end

#drawObject

Returns the value of attribute draw.



29
30
31
# File 'lib/active_data_tables/active_data_tables.rb', line 29

def draw
  @draw
end

#records_filteredObject

Returns the value of attribute records_filtered.



29
30
31
# File 'lib/active_data_tables/active_data_tables.rb', line 29

def records_filtered
  @records_filtered
end

#records_totalObject

Returns the value of attribute records_total.



29
30
31
# File 'lib/active_data_tables/active_data_tables.rb', line 29

def records_total
  @records_total
end

Instance Method Details

#to_jsonObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_data_tables/active_data_tables.rb', line 38

def to_json
  data = @data.map do |a|
    a.is_a?(OpenStruct) ? a.marshal_dump : a
  end
  Jbuilder.encode do |json|
    json.draw @draw
    json.recordsTotal @records_total
    json.recordsFiltered @records_filtered
    json.data data
  end
end