47
47
showtable (table:: AbstractMatrix ; kwargs... ) = showtable (Tables. table (table); kwargs... )
48
48
49
49
"""
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)
51
52
52
53
Return a `WebIO.Scope` that displays the provided `table`.
53
54
54
55
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.
62
68
"""
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,
64
72
dark:: Bool = false ,
65
73
title:: String = " " ,
66
74
height = :auto ,
@@ -190,19 +198,20 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}();
190
198
)
191
199
)
192
200
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
+
197
203
showfun = async ? _showtable_async! : _showtable_sync!
198
204
199
- showfun (w, schema, names, types, rows, coldefs, tablelength, id, options)
205
+ showfun (w, schema, types, rows, tablelength, id, options, option_mutator! )
200
206
201
- w
207
+ return w
202
208
end
203
209
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! )
205
211
options[:rowData ] = JSONText (table2json (schema, rows, types))
212
+
213
+ option_mutator! (options)
214
+
206
215
license = get (ENV , " AG_GRID_LICENSE_KEY" , nothing )
207
216
handler = @js function (RowNumberRenderer, agGrid)
208
217
@var gridOptions = $ options
@@ -219,7 +228,7 @@ function _showtable_sync!(w, schema, names, types, rows, coldefs, tablelength, i
219
228
onimport (w, handler)
220
229
end
221
230
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! )
223
232
rowparams = Observable (w, " rowparams" , Dict (" startRow" => 1 ,
224
233
" endRow" => 100 ,
225
234
" successCallback" => @js v -> nothing ))
@@ -246,6 +255,8 @@ function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength,
246
255
)
247
256
license = get (ENV , " AG_GRID_LICENSE_KEY" , nothing )
248
257
258
+ option_mutator! (options)
259
+
249
260
handler = @js function (RowNumberRenderer, agGrid)
250
261
@var gridOptions = $ options
251
262
@var el = document. getElementById ($ id)
0 commit comments