@@ -11,31 +11,96 @@ module DatatablesAdapter
11
11
12
12
# Read : https://datatables.net/ to understand
13
13
# the datatables option concept.
14
+ # Along with these options, a user can provide an additional option
15
+ # html_options[:table_options] to cistomize the generated table
16
+ # See the specs of daru-data_tables gem.
14
17
#
15
- # TODO : this docs must be improved
18
+ # @param data [Array, Daru::DataFrame, Daru::Vector] The data provided
19
+ # by the user to generate the datatable
20
+ # @param options [Hash] Various options provided by the user to
21
+ # incorporate in datatable
22
+ # @return [Daru::DataTables::DataTable] Returns the datatble object
23
+ #
24
+ # @example DataTable
25
+ # Set Daru::View.table_library = :googlecharts (or set adapter option)
26
+ # (Also set Daru::View.dependent_script(:googlecharts) in web
27
+ # frameworks in head tag)
28
+ # Formulate the data to visualize
29
+ # idx = Daru::Index.new ['Year', 'Sales']
30
+ # data_rows = [
31
+ # ['2004', 1000],
32
+ # ['2005', 1170],
33
+ # ['2006', 660],
34
+ # ['2007', 1030]
35
+ # ]
36
+ # df_sale_exp = Daru::DataFrame.rows(data_rows)
37
+ # df_sale_exp.vectors = idx
38
+ #
39
+ # Set the options required
40
+ # options1 = {
41
+ # html_options: {
42
+ # table_options: {
43
+ # table_thead: "<thead>
44
+ # <tr>
45
+ # <th></th>
46
+ # <th>C1</th>
47
+ # <th>C2</th>
48
+ # </tr>
49
+ # </thead>",
50
+ # width: '90%'
51
+ # }
52
+ # },
53
+ # scrollX: true
54
+ # }
55
+ # options2 = {searching: false}
56
+ #
57
+ # Draw the Daru::View::Table object.
58
+ # table = Daru::View::Table.new(df_sale_exp, options1)
59
+ # table2 = Daru::View::Table.new(df_sale_exp, options2)
60
+ # table3 = Daru::View::Table.new(df_sale_exp)
16
61
def init_table ( data = [ ] , options = { } )
17
62
@table = Daru ::DataTables ::DataTable . new ( data , options )
18
63
@table
19
64
end
20
65
66
+ # @return [String] returns code of the dependent JS and CSS file(s)
21
67
def init_script
22
68
Daru ::DataTables . init_script
23
69
end
24
70
71
+ # @param table [Daru::DataTables::DataTable] table object to access
72
+ # daru-data_table methods
73
+ # @return [String] script and table (containg thead only) tags of the
74
+ # datatable generated
25
75
def generate_body ( table )
26
76
table . to_html
27
77
end
28
78
79
+ # @param table [Daru::DataTables::DataTable] table object to access
80
+ # daru-data_table methods
81
+ # @return [void] writes the html code of the datatable to the file
82
+ # @example
83
+ # table = Daru::View::Table.new(data, options)
84
+ # table.export_html_file
29
85
def export_html_file ( table , path = './table.html' )
30
86
path = File . expand_path ( path , Dir . pwd )
31
87
str = generate_html ( table )
32
88
File . write ( path , str )
33
89
end
34
90
91
+ # @param table [Daru::DataTables::DataTable] table object to access
92
+ # daru-data_table methods
93
+ # @return [void] shows the datatable in IRuby notebook
94
+ # @example
95
+ # table = Daru::View::Table.new(data, options)
96
+ # table.show_in_iruby
35
97
def show_in_iruby ( table )
36
98
table . show_in_iruby
37
99
end
38
100
101
+ # @param table [Daru::DataTables::DataTable] table object to access
102
+ # daru-data_table methods
103
+ # @return [String] returns html code of the datatable generated
39
104
def generate_html ( table )
40
105
path = File . expand_path (
41
106
'../templates/datatables/static_html.erb' , __dir__
@@ -47,6 +112,10 @@ def generate_html(table)
47
112
ERB . new ( template ) . result ( binding )
48
113
end
49
114
115
+ # @return [void] loads the dependent JS and CSS files in IRuby notebook
116
+ # @example
117
+ # table = Daru::View::Table.new(data, options)
118
+ # table.init_iruby
50
119
def init_iruby
51
120
Daru ::DataTables . init_iruby
52
121
end
0 commit comments