Closed essenciary closed 1 year ago
Support can be added easily by taking DataFrames.jl as a dependency:
DataTable(table) = DataTable(DataFrame(table))
since DataFrames.jl itself already supports Tables.jl.
Of course a more professional solution would just use the Tables.jl interface directly to extract the data from the table type without conversion.
That's what I'm currently doing. The longer part is to move the stippleparse to DataFrames to an extension. But this will be done in two separate steps.
It's all set, we just need to merge https://github.com/GenieFramework/Stipple.jl/pull/209 and #99.
Then you will be able to use any Tables compatible type, e.g. Tables interface or TypedTables:
using Tables
t1 = Tables.table([1 2 3; 3 4 5], header = ["a", "b", "c"])
table(:dt)
# "<q-table :columns=\"dt.columns\" v-model=\"dt\" :data=\"dt.data\" row-key=\"__id\"></q-table>"
render(DataTable(t1))
# Dict{String, Any} with 2 entries:
# "data" => Dict{String, Any}[Dict("c"=>3, "__id"=>1, "b"=>2, "a"=>1), Dict("c"=>5, "__id"=>2, "b"=>4, "a"=>3)]
# "columns" => Column[Column("a", false, "a", :left, "a", true), Column("b", false, "b", :left, "b", true), Column("c", false, "c", :left, "c", true)]
or
using TypedTables
t2 = Table(a = 1:3, b = collect("abc")) # or FlexTable or DictTable
render(DataTable(t2))
# Dict{String, Any} with 2 entries:
# "data" => Dict{String, Any}[Dict("__id"=>1, "b"=>'a', "a"=>1), Dict("__id"=>2, "b"=>'b', "a"=>2), Dict("__id"=>3, "b"=>'c', "a"=>3)]
# "columns" => Column[Column("a", false, "a", :left, "a", true), Column("b", false, "b", :left, "b", true)]
And rendering of Tables compatible type is supported as well:
render(t1)
# OrderedDict{Symbol, AbstractVector} with 2 entries:
# :a => 1:3
# :b => ['a', 'b', 'c']
Thank you @hhaensel , we are looking forward to use the new feature.
@juliohm Hope this fits your needs. Please note: With the latest PR #99 DataFrames is not loaded automatically anymore. Instead all DataFrame-specific definitions are loaded via an extension. If you need to use DataFrames, the best is to load it before loading StippleUI. Otherwise rely on the new Tables API and enjoy the shorter loading time 😉
heads up: I'm almost ready, not a big deal.