Skip to content

Commit 9ba2df0

Browse files
authored
Merge pull request #41 from JuliaComputing/sp/title
add title arg
2 parents b0bf95a + 1524013 commit 9ba2df0

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/TableView.jl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ Return a `WebIO.Scope` that displays the provided `table`.
5252
5353
Optional arguments:
5454
- `dark`: Switch to a dark theme.
55+
- `title`: Displayed above the table if non-empty;
5556
- `height`/`width`: CSS attributes specifying the output height and with.
5657
- `cell_changed`: Either `nothing` or a function that takes a single argument with the fields
5758
`"new"`, `"old"`, `"row"`, and `"col"`. This function is called whenever the
5859
user edits a table field. Note that all values will be strings, so you need to
5960
do the necessary conversions yourself.
6061
"""
61-
function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); dark = false, height = :auto, width = "100%", cell_changed = nothing)
62+
function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}();
63+
dark::Bool = false,
64+
title::String = "",
65+
height = :auto,
66+
width = "100%",
67+
cell_changed = nothing
68+
)
6269
rows = Tables.rows(table)
6370
tablelength = Base.IteratorSize(rows) == Base.HasLength() ? length(rows) : nothing
6471

@@ -148,10 +155,23 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); dark
148155
end
149156

150157
id = string("grid-", string(uuid1())[1:8])
151-
w.dom = dom"div"(className = "ag-theme-balham$(dark ? "-dark" : "")",
158+
w.dom = dom"div"(
159+
dom"div"(
160+
title,
161+
style = Dict(
162+
"background-color" => dark ? "#1c1f20" : "#F5F7F7",
163+
"color" => dark ? "#F5F7F7" : "#1c1f20",
164+
"height" => isempty(title) ? "0" : "18px",
165+
"padding" => isempty(title) ? "0" : "5px",
166+
"font-family" => """-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif"""
167+
)
168+
),
169+
dom"div"(className = "ag-theme-balham$(dark ? "-dark" : "")",
152170
style = Dict("width" => to_css_size(width),
153171
"height" => to_css_size(height)),
154-
id = id)
172+
id = id
173+
)
174+
)
155175

156176
showfun = async ? _showtable_async! : _showtable_sync!
157177

src/rowNumberRenderer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function RowNumberRenderer() {}
2+
3+
RowNumberRenderer.prototype.init = function (params) {
4+
this.eGui = document.createElement('span');
5+
this.eGui.innerHTML = params.rowIndex + 1;
6+
};
7+
8+
RowNumberRenderer.prototype.getGui = function() {
9+
return this.eGui;
10+
};

0 commit comments

Comments
 (0)