From c7349160ea6f15395b21450bd59a2ed4f4e1bf72 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 12 May 2021 13:49:32 +0200 Subject: [PATCH] various API tweaks --- Project.toml | 4 ++-- ag-grid.version | 2 +- src/TableView.jl | 45 ++++++++++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Project.toml b/Project.toml index 8e7d87b..41b86ca 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "TableView" uuid = "40c74d1a-b44c-5b06-a7c1-6cbea58ea978" -version = "0.6.8" +version = "0.7.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -14,7 +14,7 @@ WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29" [compat] JSExpr = "0.4, 0.5" JSON = "0.18, 0.19, 0.20, 0.21" -Observables = "0.2,0.3" +Observables = "0.2, 0.3, 0.4" Tables = "1" WebIO = "0.8" julia = "0.7, 1" diff --git a/ag-grid.version b/ag-grid.version index 2c0a9e3..baa90a6 100644 --- a/ag-grid.version +++ b/ag-grid.version @@ -1 +1 @@ -25.0.0 +25.2.0 diff --git a/src/TableView.jl b/src/TableView.jl index b3987aa..7d8a9f8 100644 --- a/src/TableView.jl +++ b/src/TableView.jl @@ -47,20 +47,28 @@ end showtable(table::AbstractMatrix; kwargs...) = showtable(Tables.table(table); kwargs...) """ - showtable(table; dark = false, height = :auto, width = "100%", cell_changed = nothing) + showtable(table; options::Dict{Symbol, Any} = Dict{Symbol, Any}(), option_mutator! = identity, + dark = false, height = :auto, width = "100%", cell_changed = nothing) Return a `WebIO.Scope` that displays the provided `table`. Optional arguments: - - `dark`: Switch to a dark theme. - - `title`: Displayed above the table if non-empty; - - `height`/`width`: CSS attributes specifying the output height and with. - - `cell_changed`: Either `nothing` or a function that takes a single argument with the fields - `"new"`, `"old"`, `"row"`, and `"col"`. This function is called whenever the - user edits a table field. Note that all values will be strings, so you need to - do the necessary conversions yourself. + - `options`: Directly passed to agGrid's `Grid` constructor. Refer to the + [documentation](https://www.ag-grid.com/documentation/) for more info. + - `options_mutator!`: Runs on the `options` dictionary populated by TableView and allows for + customizing the grid (at your own risk -- you can break the package by + supplying invalid options). + - `dark`: Switch to a dark theme. + - `title`: Displayed above the table if non-empty; + - `height`/`width`: CSS attributes specifying the output height and with. + - `cell_changed`: Either `nothing` or a function that takes a single argument with the fields + `"new"`, `"old"`, `"row"`, and `"col"`. This function is called whenever the + user edits a table field. Note that all values will be strings, so you need to + do the necessary conversions yourself. """ -function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); +function showtable(table; + options::Dict{Symbol, Any} = Dict{Symbol, Any}(), + option_mutator! = identity, dark::Bool = false, title::String = "", height = :auto, @@ -190,19 +198,20 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); ) ) - # allow a user to modify some of the table settings using a call back function supplied in the options argument - # we need to remove the callback function key from options as it cause the JS serilization process to fail - haskey(options, :userCallbackFunc) && ((options[:userCallbackFunc])(options) ; delete!(options, :userCallbackFunc)) - + + showfun = async ? _showtable_async! : _showtable_sync! - showfun(w, schema, names, types, rows, coldefs, tablelength, id, options) + showfun(w, schema, types, rows, tablelength, id, options, option_mutator!) - w + return w end -function _showtable_sync!(w, schema, names, types, rows, coldefs, tablelength, id, options) +function _showtable_sync!(w, schema, types, rows, tablelength, id, options, option_mutator!) options[:rowData] = JSONText(table2json(schema, rows, types)) + + option_mutator!(options) + license = get(ENV, "AG_GRID_LICENSE_KEY", nothing) handler = @js function (RowNumberRenderer, agGrid) @var gridOptions = $options @@ -219,7 +228,7 @@ function _showtable_sync!(w, schema, names, types, rows, coldefs, tablelength, i onimport(w, handler) end -function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength, id, options) +function _showtable_async!(w, schema, types, rows, tablelength, id, options, option_mutator!) rowparams = Observable(w, "rowparams", Dict("startRow" => 1, "endRow" => 100, "successCallback" => @js v -> nothing)) @@ -246,6 +255,8 @@ function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength, ) license = get(ENV, "AG_GRID_LICENSE_KEY", nothing) + option_mutator!(options) + handler = @js function (RowNumberRenderer, agGrid) @var gridOptions = $options @var el = document.getElementById($id)