@@ -14,6 +14,7 @@ function __init__()
1414 for f in [" ag-grid.js" , " ag-grid.css" , " ag-grid-light.css" , " ag-grid-dark.css" ]
1515 push! (ag_grid_imports, normpath (joinpath (@__DIR__ , " .." , " deps" , " ag-grid-$(version) " , f)))
1616 end
17+ pushfirst! (ag_grid_imports, normpath (joinpath (@__DIR__ , " rowNumberRenderer.js" )))
1718end
1819
1920to_css_size (s:: AbstractString ) = s
@@ -66,7 +67,7 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); dark
6667 height = 500
6768 if tablelength != = nothing
6869 # header + footer height ≈ 40px, 28px per row
69- height = min (40 + tablelength* 28 , height)
70+ height = min (50 + tablelength* 28 , height)
7071 end
7172 end
7273
@@ -116,18 +117,30 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); dark
116117 end
117118 end
118119
119- coldefs = [(
120- headerName = n ,
121- editable = cell_changed != = nothing ,
122- headerTooltip = types[i],
123- field = n ,
124- sortable = ! async,
125- resizable = true ,
126- type = types[i] <: Union{Missing, T where T <: Number} ? " numericColumn" : nothing ,
127- filter = async ? false : types[i] <: Union{Missing, T where T <: Dates.Date} ? " agDateColumnFilter" :
128- types[i] <: Union{Missing, T where T <: Number} ? " agNumberColumnFilter" : true
120+ coldefs = [Dict (
121+ : headerName => string (n) ,
122+ : editable => cell_changed != = nothing ,
123+ : headerTooltip => string ( types[i]) ,
124+ : field => string (n) ,
125+ : sortable => ! async,
126+ : resizable => true ,
127+ : type => types[i] <: Union{Missing, T where T <: Number} ? " numericColumn" : nothing ,
128+ : filter => async ? false : types[i] <: Union{Missing, T where T <: Dates.Date} ? " agDateColumnFilter" :
129+ types[i] <: Union{Missing, T where T <: Number} ? " agNumberColumnFilter" : true ,
129130 ) for (i, n) in enumerate (names)]
130131
132+ pushfirst! (coldefs, Dict (
133+ :headerName => " Row" ,
134+ :editable => false ,
135+ :headerTooltip => " " ,
136+ :field => " __row__" ,
137+ :sortable => ! async,
138+ :resizable => true ,
139+ :type => " numericColumn" ,
140+ :cellRenderer => " rowNumberRenderer" ,
141+ :filter => false
142+ ))
143+
131144 options[:onCellValueChanged ] = onCellValueChanged
132145 options[:columnDefs ] = coldefs
133146 options[:multiSortKey ] = " ctrl"
@@ -162,10 +175,15 @@ end
162175
163176function _showtable_sync! (w, schema, names, types, rows, coldefs, tablelength, id, options)
164177 options[:rowData ] = JSONText (table2json (schema, rows, types))
165- handler = @js function (agGrid)
178+ handler = @js function (RowNumberRenderer, agGrid)
166179 @var gridOptions = $ options
167180 @var el = document. getElementById ($ id)
181+ gridOptions. components = Dict (
182+ " rowNumberRenderer" => RowNumberRenderer
183+ )
168184 this. table = @new agGrid. Grid (el, gridOptions)
185+
186+ gridOptions. columnApi. autoSizeColumn (" __row__" )
169187 gridOptions. columnApi. autoSizeColumns ($ names)
170188 end
171189 onimport (w, handler)
@@ -197,10 +215,16 @@ function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength,
197215 " rowCount" => tablelength
198216 )
199217
200- handler = @js function (agGrid)
218+ handler = @js function (RowNumberRenderer, agGrid)
201219 @var gridOptions = $ options
202220 @var el = document. getElementById ($ id)
221+
222+ gridOptions. components = Dict (
223+ " rowNumberRenderer" => RowNumberRenderer
224+ )
225+
203226 this. table = @new agGrid. Grid (el, gridOptions)
227+ gridOptions. columnApi. autoSizeColumn (" __row__" )
204228 gridOptions. columnApi. autoSizeColumns ($ names)
205229 end
206230 onimport (w, handler)
0 commit comments