4747showtable (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
5253Return a `WebIO.Scope` that displays the provided `table`.
5354
5455Optional 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
202208end
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)
220229end
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