@@ -58,7 +58,7 @@ Optional arguments:
5858 user edits a table field. Note that all values will be strings, so you need to
5959 do the necessary conversions yourself.
6060"""
61- function showtable (table; dark = false , height = :auto , width = " 100%" , cell_changed = nothing )
61+ function showtable (table, options :: Dict{Symbol, Any} = Dict {Symbol, Any} () ; dark = false , height = :auto , width = " 100%" , cell_changed = nothing )
6262 rows = Tables. rows (table)
6363 tablelength = Base. IteratorSize (rows) == Base. HasLength () ? length (rows) : nothing
6464
@@ -128,6 +128,25 @@ function showtable(table; dark = false, height = :auto, width = "100%", cell_cha
128128 types[i] <: Union{Missing, T where T <: Number} ? " agNumberColumnFilter" : true
129129 ) for (i, n) in enumerate (names)]
130130
131+ options[:onCellValueChanged ] = onCellValueChanged
132+ options[:columnDefs ] = coldefs
133+ options[:multiSortKey ] = " ctrl"
134+
135+ for e in [" onCellClicked" , " onCellDoubleClicked" , " onRowClicked" , " onCellFocused" , " onCellKeyDown" ]
136+ o = Observable {Any} (w, e, nothing )
137+ handler = @js function (ev)
138+ @var x = Dict ()
139+ if ev. rowIndex != = undefined
140+ x[" rowIndex" ] = ev. rowIndex + 1
141+ end
142+ if ev. colDef != = undefined
143+ x[" column" ] = ev. colDef. headerName
144+ end
145+ $ o[] = x
146+ end
147+ options[Symbol (e)] = handler
148+ end
149+
131150 id = string (" grid-" , string (uuid1 ())[1 : 8 ])
132151 w. dom = dom " div" (className = " ag-theme-balham$(dark ? " -dark" : " " ) " ,
133152 style = Dict (" width" => to_css_size (width),
@@ -136,19 +155,13 @@ function showtable(table; dark = false, height = :auto, width = "100%", cell_cha
136155
137156 showfun = async ? _showtable_async! : _showtable_sync!
138157
139- showfun (w, names, types, rows, coldefs, tablelength, dark, id, onCellValueChanged )
158+ showfun (w, names, types, rows, coldefs, tablelength, id, options )
140159
141160 w
142161end
143162
144- function _showtable_sync! (w, names, types, rows, coldefs, tablelength, dark, id, onCellValueChanged)
145- options = Dict (
146- :onCellValueChanged => onCellValueChanged,
147- :rowData => JSONText (table2json (rows, names, types)),
148- :columnDefs => coldefs,
149- :multiSortKey => " ctrl" ,
150- )
151-
163+ function _showtable_sync! (w, names, types, rows, coldefs, tablelength, id, options)
164+ options[:rowData ] = JSONText (table2json (rows, names, types))
152165 handler = @js function (agGrid)
153166 @var gridOptions = $ options
154167 @var el = document. getElementById ($ id)
@@ -159,7 +172,7 @@ function _showtable_sync!(w, names, types, rows, coldefs, tablelength, dark, id,
159172end
160173
161174
162- function _showtable_async! (w, names, types, rows, coldefs, tablelength, dark, id, onCellValueChanged )
175+ function _showtable_async! (w, names, types, rows, coldefs, tablelength, id, options )
163176 rowparams = Observable (w, " rowparams" , Dict (" startRow" => 1 ,
164177 " endRow" => 100 ,
165178 " successCallback" => @js v -> nothing ))
@@ -172,22 +185,17 @@ function _showtable_async!(w, names, types, rows, coldefs, tablelength, dark, id
172185 ($ rowparams[]). successCallback (val, $ (tablelength))
173186 end )
174187
175- options = Dict (
176- :onCellValueChanged => onCellValueChanged,
177- :columnDefs => coldefs,
178- :maxConcurrentDatasourceRequests => 1 ,
179- :cacheBlockSize => 1000 ,
180- :maxBlocksInCache => 100 ,
181- :multiSortKey => " ctrl" ,
182- :rowModelType => " infinite" ,
183- :datasource => Dict (
184- " getRows" =>
185- @js function (rowParams)
186- $ rowparams[] = rowParams
187- end
188- ,
189- " rowCount" => tablelength
190- )
188+ options[:maxConcurrentDatasourceRequests ] = 1
189+ options[:cacheBlockSize ] = 1000
190+ options[:maxBlocksInCache ] = 100
191+ options[:rowModelType ] = " infinite"
192+ options[:datasource ] = Dict (
193+ " getRows" =>
194+ @js function (rowParams)
195+ $ rowparams[] = rowParams
196+ end
197+ ,
198+ " rowCount" => tablelength
191199 )
192200
193201 handler = @js function (agGrid)
0 commit comments