Skip to content

Commit 6a49528

Browse files
authored
Merge pull request #76 from JuliaComputing/sp/updates
various API tweaks
2 parents a7219f9 + c734916 commit 6a49528

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TableView"
22
uuid = "40c74d1a-b44c-5b06-a7c1-6cbea58ea978"
3-
version = "0.6.8"
3+
version = "0.7.0"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -14,7 +14,7 @@ WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
1414
[compat]
1515
JSExpr = "0.4, 0.5"
1616
JSON = "0.18, 0.19, 0.20, 0.21"
17-
Observables = "0.2,0.3"
17+
Observables = "0.2, 0.3, 0.4"
1818
Tables = "1"
1919
WebIO = "0.8"
2020
julia = "0.7, 1"

ag-grid.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
25.0.0
1+
25.2.0

src/TableView.jl

+28-17
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,28 @@ end
4747
showtable(table::AbstractMatrix; kwargs...) = showtable(Tables.table(table); kwargs...)
4848

4949
"""
50-
showtable(table; dark = false, height = :auto, width = "100%", cell_changed = nothing)
50+
showtable(table; options::Dict{Symbol, Any} = Dict{Symbol, Any}(), option_mutator! = identity,
51+
dark = false, height = :auto, width = "100%", cell_changed = nothing)
5152
5253
Return a `WebIO.Scope` that displays the provided `table`.
5354
5455
Optional arguments:
55-
- `dark`: Switch to a dark theme.
56-
- `title`: Displayed above the table if non-empty;
57-
- `height`/`width`: CSS attributes specifying the output height and with.
58-
- `cell_changed`: Either `nothing` or a function that takes a single argument with the fields
59-
`"new"`, `"old"`, `"row"`, and `"col"`. This function is called whenever the
60-
user edits a table field. Note that all values will be strings, so you need to
61-
do the necessary conversions yourself.
56+
- `options`: Directly passed to agGrid's `Grid` constructor. Refer to the
57+
[documentation](https://www.ag-grid.com/documentation/) for more info.
58+
- `options_mutator!`: Runs on the `options` dictionary populated by TableView and allows for
59+
customizing the grid (at your own risk -- you can break the package by
60+
supplying invalid options).
61+
- `dark`: Switch to a dark theme.
62+
- `title`: Displayed above the table if non-empty;
63+
- `height`/`width`: CSS attributes specifying the output height and with.
64+
- `cell_changed`: Either `nothing` or a function that takes a single argument with the fields
65+
`"new"`, `"old"`, `"row"`, and `"col"`. This function is called whenever the
66+
user edits a table field. Note that all values will be strings, so you need to
67+
do the necessary conversions yourself.
6268
"""
63-
function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}();
69+
function showtable(table;
70+
options::Dict{Symbol, Any} = Dict{Symbol, Any}(),
71+
option_mutator! = identity,
6472
dark::Bool = false,
6573
title::String = "",
6674
height = :auto,
@@ -190,19 +198,20 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}();
190198
)
191199
)
192200

193-
# allow a user to modify some of the table settings using a call back function supplied in the options argument
194-
# we need to remove the callback function key from options as it cause the JS serilization process to fail
195-
haskey(options, :userCallbackFunc) && ((options[:userCallbackFunc])(options) ; delete!(options, :userCallbackFunc))
196-
201+
202+
197203
showfun = async ? _showtable_async! : _showtable_sync!
198204

199-
showfun(w, schema, names, types, rows, coldefs, tablelength, id, options)
205+
showfun(w, schema, types, rows, tablelength, id, options, option_mutator!)
200206

201-
w
207+
return w
202208
end
203209

204-
function _showtable_sync!(w, schema, names, types, rows, coldefs, tablelength, id, options)
210+
function _showtable_sync!(w, schema, types, rows, tablelength, id, options, option_mutator!)
205211
options[:rowData] = JSONText(table2json(schema, rows, types))
212+
213+
option_mutator!(options)
214+
206215
license = get(ENV, "AG_GRID_LICENSE_KEY", nothing)
207216
handler = @js function (RowNumberRenderer, agGrid)
208217
@var gridOptions = $options
@@ -219,7 +228,7 @@ function _showtable_sync!(w, schema, names, types, rows, coldefs, tablelength, i
219228
onimport(w, handler)
220229
end
221230

222-
function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength, id, options)
231+
function _showtable_async!(w, schema, types, rows, tablelength, id, options, option_mutator!)
223232
rowparams = Observable(w, "rowparams", Dict("startRow" => 1,
224233
"endRow" => 100,
225234
"successCallback" => @js v -> nothing))
@@ -246,6 +255,8 @@ function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength,
246255
)
247256
license = get(ENV, "AG_GRID_LICENSE_KEY", nothing)
248257

258+
option_mutator!(options)
259+
249260
handler = @js function (RowNumberRenderer, agGrid)
250261
@var gridOptions = $options
251262
@var el = document.getElementById($id)

0 commit comments

Comments
 (0)