Please visit https://github.com/Shekharrajak/daru-data_tables for updated API and examples. It works in Ruby web application framework but there is already an issue open for IRuby notebook: https://github.com/Shekharrajak/daru-data_tables/issues/2
require 'daru/data_tables'
require 'daru'
/home/shekharrajak/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/bundler/gems/daru-data_tables-af3460a049da/lib/daru/data_tables/version.rb:3: warning: already initialized constant Daru::View::VERSION /home/shekharrajak/Documents/githubRepos/sciruby/windows-daru-view/daru-view/lib/daru/view/version.rb:3: warning: previous definition of VERSION was here
true
df = 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])
a | b | c | |
---|---|---|---|
one | 1 | 11 | 11 |
two | 2 | 12 | 22 |
three | 3 | 13 | 33 |
four | 4 | 14 | 44 |
five | 5 | 15 | 55 |
# Please refer: https://github.com/Shekharrajak/daru-data_tables/issues/2
# Daru::View::DataTables.init_iruby
# t = DataTables::DataTable.new(pageLength: 3)
# t.to_html
# t.to_html(id='table_id1')
# table_opts = {
# class: "display",
# cellspacing: "0",
# width: "100%"
# }
# options ={
# table_options: table_opts
# }
# t.to_html(id='table_id1', options)
# id is automatically added into table_options
# options
# options[:table_options][:table_html] = df.to_html_thead + df.to_html_tbody
# html_code = t.to_html(id='table_id1', options)
# Fix me: It is showing normal html code. That means DataTables js and css is not working or loading.
# IRuby.html html_code
# html_code.html_safe
# Fix me: It is showing normal html code. That means DataTables js and css is not working or loading.
# IRuby.html html_code
# t_opts = {
# data: [[1,1,1],
# [1,2,3],
# [11,12,13],
# [1,2,3],
# [11,12,13],
# [1,2,3],
# [11,12,13]
# ],
# pageLength: 4
# }
# table_from_array = DataTables::DataTable.new(t_opts)
# table_opts = {
# class: "display",
# cellspacing: "0",
# width: "50%",
# table_html: "
# <thead>
# <tr>
# <th>Num1 </th>
# <th>Num2 </th>
# <th>Num3 </th>
# </tr>
# </thead>"
# }
# options = {
# table_options: table_opts
# }
# html_code_array_sorted = table_from_array.to_html(id='table_id4', options)
# IRuby.html html_code_array_sorted
# IRuby.display(IRuby.javascript(table_from_array.to_html('id1')))
# IRuby.html(table_from_array.to_html(id='table_id4', options))
# table_html = "
# <table id='id1'>
# <thead>
# <tr>
# <th>Num1 </th>
# <th>Num2 </th>
# <th>Num3 </th>
# </tr>
# </thead>
# </table>"
# IRuby.html table_html