Skip to content

Commit

Permalink
Merge pull request #76 from JuliaComputing/sp/updates
Browse files Browse the repository at this point in the history
various API tweaks
  • Loading branch information
pfitzseb authored May 12, 2021
2 parents a7219f9 + c734916 commit 6a49528
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ag-grid.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25.0.0
25.2.0
45 changes: 28 additions & 17 deletions src/TableView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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)
Expand Down

2 comments on commit 6a49528

@pfitzseb
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/36575

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" 6a49528527d81a127a741674e2b9cfd176edb01d
git push origin v0.7.0

Please sign in to comment.