1- import * as widgets from '@jupyter-widgets/base' ;
1+ import * as widgets from '@jupyter-widgets/base' ;
2+ import * as d3 from 'd3-format' ;
23import { cloneDeep , extend , includes as contains , each , debounce , times , map , unzip as transpose } from 'lodash' ;
34import { semver_range } from './version' ;
45import { RendererModel } from './renderer' ;
@@ -143,8 +144,8 @@ let SheetModel = widgets.DOMWidgetModel.extend({
143144 cell_data . options [ 'readOnly' ] = cell . get ( 'read_only' ) ;
144145 if ( cell . get ( 'choice' ) != null )
145146 cell_data . options [ 'source' ] = cell . get ( 'choice' )
146- if ( cell . get ( 'numeric_format' ) && cell . get ( 'type' ) == 'numeric' )
147- cell_data . options [ 'numericFormat' ] = { 'pattern' : cell . get ( 'numeric_format' ) } ;
147+ if ( cell . get ( 'numeric_format' ) && ( cell . get ( 'type' ) == 'int' || cell . get ( 'type' ) == 'float' ) )
148+ cell_data . options [ 'numericFormat' ] = cell . get ( 'numeric_format' ) ;
148149 if ( cell . get ( 'date_format' ) && cell . get ( 'type' ) == 'date' ) {
149150 cell_data . options [ 'correctFormat' ] = true ;
150151 cell_data . options [ 'dateFormat' ] = cell . get ( 'date_format' ) || cell_data . options [ 'dateFormat' ] ;
@@ -262,7 +263,7 @@ let put_values2d = function(grid, values) {
262263 }
263264} ;
264265
265- // calls the original renderer and then applies custom styling
266+ // Custom styled renderer that applies the default renderer then apply the given style on the cell
266267( Handsontable . renderers as any ) . registerRenderer ( 'styled' , function customRenderer ( hotInstance , td , row , column , prop , value , cellProperties ) {
267268 let name = cellProperties . original_renderer || cellProperties . type || 'text' ;
268269 let original_renderer = ( Handsontable . renderers as any ) . getRenderer ( name ) ;
@@ -272,6 +273,34 @@ let put_values2d = function(grid, values) {
272273 } ) ;
273274} ) ;
274275
276+
277+ // Register `int` cell type
278+ let int_editor = Handsontable . editors . TextEditor . prototype . extend ( ) ;
279+
280+ function int_renderer ( hotInstance , td , row , column , prop , value , cellProperties ) {
281+ const numeric_format = cellProperties . numericFormat || 'd' ;
282+ td . innerHTML = d3 . format ( numeric_format ) ( value ) ;
283+ }
284+
285+ function int_validator ( query , callback ) {
286+ let is_integer = false ;
287+ if ( typeof query == 'number' ) {
288+ is_integer = Number . isInteger ( query ) ;
289+ } else {
290+ is_integer = Number . isInteger ( parseFloat ( query ) ) ;
291+ }
292+
293+ console . log ( 'is_integer?' , query , is_integer ) ;
294+ callback ( is_integer ) ;
295+ }
296+
297+ ( Handsontable . cellTypes as any ) . registerCellType ( 'int' , {
298+ editor : int_editor ,
299+ renderer : int_renderer ,
300+ validator : int_validator ,
301+ allowInvalid : false
302+ } ) ;
303+
275304let SheetView = widgets . DOMWidgetView . extend ( {
276305 render : function ( ) {
277306 // this.widget_view_promises = {}
0 commit comments