Skip to content

Commit 52aaecd

Browse files
author
Shashi Gowda
committed
fix #2 and #3
1 parent a3c2d4c commit 52aaecd

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/TableView.jl

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,38 @@ module TableView
22

33
using WebIO
44
using JuliaDB
5+
using DataValues
56

67
import JuliaDB: DNDSparse, DNextTable, NextTable
78

89
function JuliaDB.subtable(t::DNextTable, r)
910
table(collect(rows(t)[r]), pkey=t.pkey)
1011
end
1112

13+
showna(xs) = xs
14+
function showna(xs::DataValueArray)
15+
map(xs) do x
16+
isnull(x) ? "NA" : get(x)
17+
end
18+
end
19+
20+
function showna(xs::Columns)
21+
rows(map(showna, columns(xs)))
22+
end
23+
1224
function showtable(t::Union{DNextTable, NextTable}; rows=1:100, colopts=Dict(), kwargs...)
1325
w = Widget(dependencies=["https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.34.0/handsontable.full.js",
1426
"https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.34.0/handsontable.full.css"])
1527
data = Observable{Any}(w, "data", [])
1628

17-
subt = JuliaDB.subtable(t, rows)
29+
trunc_rows = max(1, first(rows)):min(length(t), last(rows))
30+
subt = JuliaDB.subtable(t, trunc_rows)
1831

1932
headers = colnames(subt)
2033
cols = [merge(Dict(:data=>n), get(colopts, n, Dict())) for n in headers]
2134

2235
options = Dict(
23-
:data => collect(JuliaDB.rows(subt)),
36+
:data => showna(collect(JuliaDB.rows(subt))),
2437
:colHeaders => headers,
2538
:modifyColWidth => @js(w -> w > 300 ? 300 : w),
2639
:modifyRowHeight => @js(h -> h > 60 ? 50 : h),
@@ -49,20 +62,23 @@ function showtable(t::Union{DNextTable, NextTable}; rows=1:100, colopts=Dict(),
4962
ondependencies(w, handler)
5063
w()
5164
end
65+
5266
function showtable(t::Union{DNDSparse, NDSparse}; rows=1:100, colopts=Dict(), kwargs...)
5367
w = Widget(dependencies=["https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.34.0/handsontable.full.js",
5468
"https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.34.0/handsontable.full.css"])
5569
data = Observable{Any}(w, "data", [])
5670

57-
ks = keys(t)[rows]
58-
vs = values(t)[rows]
71+
trunc_rows = max(1, first(rows)):min(length(t), last(rows))
72+
73+
ks = keys(t)[trunc_rows]
74+
vs = values(t)[trunc_rows]
5975

6076
if !isa(keys(t), Columns)
6177
ks = collect(ks)
6278
vs = collect(vs)
6379
end
6480

65-
subt = NDSparse(ks, vs)
81+
subt = NDSparse(showna(ks), showna(vs))
6682

6783
headers = colnames(subt)
6884
cols = [merge(Dict(:data=>n), get(colopts, n, Dict())) for n in headers]

0 commit comments

Comments
 (0)