1
1
module TableView
2
- using Tables, WebIO, JSExpr, JSON, Dates
2
+ using Tables, TableTraits, IteratorInterfaceExtensions
3
+ using WebIO, JSExpr, JSON, Dates
3
4
4
5
function showtable (x; dark = false )
5
- w = Scope (imports= [" https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.noStyle.js" ,
6
- " https://unpkg.com/ag-grid-community/dist/styles/ag-grid.css" ,
7
- " https://unpkg.com/ag-grid-community/dist/styles/ag-theme-balham$(dark ? " -dark" : " " ) .css" ,])
6
+ if Tables. istable (typeof (x))
7
+ return _showtable (x, dark)
8
+ elseif TableTraits. isiterabletable (x)
9
+ it = IteratorInterfaceExtensions. getiterator (x)
10
+ return _showtable (Tables. DataValueUnwrapper (it), dark)
11
+ end
12
+ throw (ArgumentError (" Argument is not a table." ))
13
+ end
8
14
9
- schema = Tables. schema (x)
15
+ function _showtable (table, dark)
16
+ schema = Tables. schema (table)
10
17
names = schema. names
11
18
types = schema. types
19
+ rows = Tables. rows (table)
20
+
21
+ w = Scope (imports= [" https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.noStyle.js" ,
22
+ " https://unpkg.com/ag-grid-community/dist/styles/ag-grid.css" ,
23
+ " https://unpkg.com/ag-grid-community/dist/styles/ag-theme-balham$(dark ? " -dark" : " " ) .css" ,])
12
24
13
25
coldefs = [(
14
26
headerName = n,
27
+ headerTooltip = types[i],
15
28
field = n,
16
29
type = types[i] <: Union{Missing, T where T <: Number} ? " numericColumn" : nothing ,
17
30
filter = types[i] <: Union{Missing, T where T <: Dates.Date} ? " agDateColumnFilter" :
18
31
types[i] <: Union{Missing, T where T <: Number} ? " agNumberColumnFilter" : nothing
19
32
) for (i, n) in enumerate (names)]
20
33
21
34
options = Dict (
22
- :rowData => table2json (x ),
35
+ :rowData => table2json (rows, names, types ),
23
36
:columnDefs => coldefs,
24
37
:enableSorting => true ,
25
38
:enableFilter => true ,
@@ -35,22 +48,17 @@ function showtable(x; dark = false)
35
48
end
36
49
onimport (w, handler)
37
50
w. dom = dom " div#grid" (className = " ag-theme-balham$(dark ? " -dark" : " " ) " ,
38
- style= Dict (:position => " absolute" ,
39
- :top => " 0" ,
40
- :left => " 0" ,
41
- :width => " 100%" ,
42
- :height => " 100%" ,
43
- :minHeight => " 200px" ))
51
+ style= Dict (:width => " 100%" ,
52
+ " min-width" => " 400px" ,
53
+ :height => " 800px" ))
44
54
w
45
55
end
46
56
47
57
# directly write JSON instead of allocating temporary dicts etc
48
- function table2json (table)
49
- names = Tables. schema (table). names
50
-
58
+ function table2json (rows, names, types)
51
59
io = IOBuffer ()
52
60
print (io, ' [' )
53
- for row in Tables . rows (table)
61
+ for row in rows
54
62
print (io, ' {' )
55
63
i = 1
56
64
for col in Tables. eachcolumn (row)
0 commit comments