Skip to content

Commit c40a49b

Browse files
committed
misc updates
1 parent b97defd commit c40a49b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/TableView.jl

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module TableView
2-
using Tables, TableTraits, IteratorInterfaceExtensions
3-
using WebIO, JSExpr, JSON, Dates
2+
3+
using Tables
4+
using WebIO, JSExpr, JSON, Dates, UUIDs
45
using Observables: @map
56

67
const ag_grid_imports = []
@@ -12,18 +13,11 @@ function __init__()
1213
end
1314
end
1415

15-
function showtable(x; dark = false)
16-
iit = TableTraits.isiterabletable(x)
17-
if Tables.istable(typeof(x))
18-
return _showtable(x, dark)
19-
elseif ismissing(iit) || iit
20-
it = IteratorInterfaceExtensions.getiterator(x)
21-
return _showtable(Tables.DataValueUnwrapper(it), dark)
16+
function showtable(table; dark = false, height = 500)
17+
if !Tables.istable(typeof(table))
18+
throw(ArgumentError("Argument is not a table."))
2219
end
23-
throw(ArgumentError("Argument is not a table."))
24-
end
2520

26-
function _showtable(table, dark)
2721
tablelength = Base.IteratorSize(table) == Base.HasLength() ? length(Tables.rows(table)) : nothing
2822

2923
rows = Tables.rows(table)
@@ -49,17 +43,19 @@ function _showtable(table, dark)
4943
types[i] <: Union{Missing, T where T <: Number} ? "agNumberColumnFilter" : nothing
5044
) for (i, n) in enumerate(names)]
5145

52-
tablelength === nothing || tablelength > 10_000 ? _showtable_async!(w, names, types, rows, coldefs, tablelength, dark) :
53-
_showtable_sync!(w, names, types, rows, coldefs, tablelength, dark)
46+
id = string("grid-", string(uuid1())[1:8])
47+
w.dom = dom"div"(className = "ag-theme-balham$(dark ? "-dark" : "")",
48+
style = Dict("width" => "100%",
49+
"height" => "$(height)px"),
50+
id = id)
51+
52+
tablelength === nothing || tablelength > 10_000 ? _showtable_async!(w, names, types, rows, coldefs, tablelength, dark, id) :
53+
_showtable_sync!(w, names, types, rows, coldefs, tablelength, dark, id)
5454

55-
w.dom = dom"div#grid"(className = "ag-theme-balham$(dark ? "-dark" : "")",
56-
style = Dict("width" => "100%",
57-
"height" => "100%",
58-
"min-height" => "200px"))
5955
w
6056
end
6157

62-
function _showtable_sync!(w, names, types, rows, coldefs, tablelength, dark)
58+
function _showtable_sync!(w, names, types, rows, coldefs, tablelength, dark, id)
6359
options = Dict(
6460
:rowData => JSONText(table2json(rows, names, types)),
6561
:columnDefs => coldefs,
@@ -71,14 +67,15 @@ function _showtable_sync!(w, names, types, rows, coldefs, tablelength, dark)
7167

7268
handler = @js function (agGrid)
7369
@var gridOptions = $options
74-
this.table = @new agGrid.Grid(this.dom.querySelector("#grid"), gridOptions)
70+
@var el = document.getElementById($id)
71+
this.table = @new agGrid.Grid(el, gridOptions)
7572
gridOptions.columnApi.autoSizeColumns($names)
7673
end
7774
onimport(w, handler)
7875
end
7976

8077

81-
function _showtable_async!(w, names, types, rows, coldefs, tablelength, dark)
78+
function _showtable_async!(w, names, types, rows, coldefs, tablelength, dark, id)
8279
rowparams = Observable(w, "rowparams", Dict("startRow" => 1,
8380
"endRow" => 100,
8481
"successCallback" => @js v -> nothing))
@@ -113,7 +110,8 @@ function _showtable_async!(w, names, types, rows, coldefs, tablelength, dark)
113110

114111
handler = @js function (agGrid)
115112
@var gridOptions = $options
116-
this.table = @new agGrid.Grid(this.dom.querySelector("#grid"), gridOptions)
113+
@var el = document.getElementById($id)
114+
this.table = @new agGrid.Grid(el, gridOptions)
117115
gridOptions.columnApi.autoSizeColumns($names)
118116
end
119117
onimport(w, handler)

0 commit comments

Comments
 (0)