@@ -58,7 +58,7 @@ Optional arguments:
58
58
user edits a table field. Note that all values will be strings, so you need to
59
59
do the necessary conversions yourself.
60
60
"""
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 )
62
62
rows = Tables. rows (table)
63
63
tablelength = Base. IteratorSize (rows) == Base. HasLength () ? length (rows) : nothing
64
64
@@ -128,6 +128,25 @@ function showtable(table; dark = false, height = :auto, width = "100%", cell_cha
128
128
types[i] <: Union{Missing, T where T <: Number} ? " agNumberColumnFilter" : true
129
129
) for (i, n) in enumerate (names)]
130
130
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
+
131
150
id = string (" grid-" , string (uuid1 ())[1 : 8 ])
132
151
w. dom = dom " div" (className = " ag-theme-balham$(dark ? " -dark" : " " ) " ,
133
152
style = Dict (" width" => to_css_size (width),
@@ -136,19 +155,13 @@ function showtable(table; dark = false, height = :auto, width = "100%", cell_cha
136
155
137
156
showfun = async ? _showtable_async! : _showtable_sync!
138
157
139
- showfun (w, names, types, rows, coldefs, tablelength, dark, id, onCellValueChanged )
158
+ showfun (w, names, types, rows, coldefs, tablelength, id, options )
140
159
141
160
w
142
161
end
143
162
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))
152
165
handler = @js function (agGrid)
153
166
@var gridOptions = $ options
154
167
@var el = document. getElementById ($ id)
@@ -159,7 +172,7 @@ function _showtable_sync!(w, names, types, rows, coldefs, tablelength, dark, id,
159
172
end
160
173
161
174
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 )
163
176
rowparams = Observable (w, " rowparams" , Dict (" startRow" => 1 ,
164
177
" endRow" => 100 ,
165
178
" successCallback" => @js v -> nothing ))
@@ -172,22 +185,17 @@ function _showtable_async!(w, names, types, rows, coldefs, tablelength, dark, id
172
185
($ rowparams[]). successCallback (val, $ (tablelength))
173
186
end )
174
187
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
191
199
)
192
200
193
201
handler = @js function (agGrid)
0 commit comments