Skip to content

Commit

Permalink
Merge pull request #10 from Prakriti-nith/datatables
Browse files Browse the repository at this point in the history
Added datatables examples
  • Loading branch information
Prakriti-nith authored Jul 23, 2018
2 parents 79fee6e + 61ef4a9 commit 06de8b8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
62 changes: 38 additions & 24 deletions demo_rails/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,59 +282,73 @@ def googlecharts
def datatables
# need to give name, otherwise generated thead html code will not work.
# Because no name means no thead in vector.
dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], name: 'series1'
dv = Daru::Vector.new [1, 2, 3, 4, 5, 6], name: 'series1'
options = {
adapter: :datatables,
html_options: {
table_options: {
table_thead: "<thead>
<tr>
<th></th>
<th>Demo Column Name</th>
</tr>
</thead>",
width: '90%'
}
}
}
# default adapter is nyaplot only
@dt_dv = Daru::View::Table.new(dv, pageLength: 3, adapter: :datatables)
@dt_dv_html = @dt_dv.div
@dt_dv = Daru::View::Table.new(dv, options)

df1 = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
c: [11,22,33,44,55]},
order: [:a, :b, :c],
index: [:one, :two, :three, :four, :five])
@dt_df1 = Daru::View::Table.new(df1, pageLength: 3, adapter: :datatables)
@dt_df1_html = @dt_df1.div
options2 = {
adapter: :datatables,
html_options: {
table_options: {
cellspacing: '0',
width: "100%"
}
}
}
@dt_df1 = Daru::View::Table.new(df1, options2)

df2 = Daru::DataFrame.new({
a: [1, 3, 5, 7, 5, 0],
b: [1, 5, 2, 5, 1, 0],
c: [1, 6, 7, 2, 6, 0]
}, index: 'a'..'f')
@dt_df2 = Daru::View::Table.new(df2, pageLength: 3, adapter: :datatables)
@dt_df2_html = @dt_df2.div
# user can change the table options using following code :
#
# table_opts = {
# class: "display",
# cellspacing: "0",
# width: "50%",
# table_html: 'new table thead and tbody html code'
# }
# options = {
# table_options: table_opts
# }
#
# @dt_df2.table.to_html(id='id1', options)

dv_arr = [:a, :a, :a, :b, :b, :c]

dv_arr = [1, 2, 3, 4, 5, 6]
@dt_dv_arr = Daru::View::Table.new(dv_arr, pageLength: 3, adapter: :datatables)
@dt_dv_arr_html = @dt_dv_arr.div

df1_arr = [
[11,12,13,14,15],
[1,2,3,4,5],
[11,22,33,44,55]
]
@dt_df1_arr = Daru::View::Table.new(df1_arr, pageLength: 3, adapter: :datatables)
@dt_df1_arr_html = @dt_df1_arr.div

df2_arr = [
[1, 3, 5, 7, 5, 0],
[1, 5, 2, 5, 1, 0],
[1, 6, 7, 2, 6, 0]
]
@dt_df2_arr = Daru::View::Table.new(df2_arr, pageLength: 3, adapter: :datatables)
@dt_df2_arr_html = @dt_df2_arr.div

data = []
for i in 0..100000
data << i
end
options = {
searching: false,
pageLength: 7,
adapter: :datatables
}
@table_array_large = Daru::View::Table.new(data, options)
end


Expand Down
32 changes: 21 additions & 11 deletions demo_rails/app/views/application/datatables.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<h3> Large set of data: </h3>
<p>
<b>Data : </b>
A large set of data
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @table_array_large.div %></div>
</p>

<br>

<h3> Daru DataFrame: </h3>
<p style="color:blue;width: 100px;">
<b>Data : </b>
<%=raw @dt_df2.data.to_html %>
<%=raw @dt_df2.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @dt_df2_html %></div>
<div style="width: 500px;"><%=raw @dt_df2.div %></div>

</p>

Expand All @@ -17,23 +28,23 @@
<h3> Daru DataFrame: </h3>
<p>
<b>Data : </b>
<%=raw @dt_df1.data.to_html %>
<%=raw @dt_df1.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @dt_df1_html %></div>
<div style="width: 500px;"><%=raw @dt_df1.div %></div>
</p>

<br>

<h3> Daru Vector: </h3>
<p>
<b>Data : </b>
<%=raw @dt_dv.data.to_html %>
<%=raw @dt_dv.data %>
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @dt_dv_html %></div>
<div style="width: 500px;"><%=raw @dt_dv.div %></div>
</p>
<br>

Expand All @@ -47,7 +58,7 @@
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @dt_df2_arr_html %></div>
<div style="width: 500px;"><%=raw @dt_df2_arr.div %></div>
</p>


Expand All @@ -61,7 +72,7 @@
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @dt_df1_arr_html %></div>
<div style="width: 500px;"><%=raw @dt_df1_arr.div %></div>
</p>

<br>
Expand All @@ -73,8 +84,7 @@
<br>
<b>Table : </b>
<br>
<div style="width: 500px;"><%=raw @dt_dv_arr_html %></div>
<div style="width: 500px;"><%=raw @dt_dv_arr.div %></div>
</p>
<br>


<br>

0 comments on commit 06de8b8

Please sign in to comment.