@@ -342,12 +342,51 @@ let SheetView = widgets.DOMWidgetView.extend({
342
342
rowHeaders : true ,
343
343
colHeaders : true ,
344
344
search : true ,
345
+ columnSorting : {
346
+ sortEmptyCells : false ,
347
+ indicator : true ,
348
+ headerAction : true ,
349
+ compareFunctionFactory : this . _compareFunctionFactory
350
+ } ,
345
351
cells : ( ...args ) => this . _cell ( ...args ) ,
346
352
afterChange : ( changes , source ) => { this . _on_change ( changes , source ) ; } ,
347
353
afterRemoveCol : ( changes , source ) => { this . _on_change_grid ( changes , source ) ; } ,
348
354
afterRemoveRow : ( changes , source ) => { this . _on_change_grid ( changes , source ) ; }
349
355
} , this . _hot_settings ( ) ) ) ;
350
356
} ,
357
+ _compareFunctionFactory : function ( sortOrder , columnMeta ) {
358
+ return function ( value , nextValue ) {
359
+ let a , b ;
360
+ if ( sortOrder == 'desc' ) {
361
+ a = value ;
362
+ b = nextValue ;
363
+ } else {
364
+ a = nextValue ;
365
+ b = value ;
366
+ }
367
+
368
+ if ( a instanceof widgets . WidgetModel ) {
369
+ a = a . get ( "value" ) ;
370
+ }
371
+
372
+ if ( b instanceof widgets . WidgetModel ) {
373
+ b = b . get ( "value" ) ;
374
+ }
375
+
376
+ if ( a == undefined || b == undefined ) {
377
+ return 0 ;
378
+ }
379
+
380
+ if ( a < b ) {
381
+ return - 1 ;
382
+ }
383
+ if ( a > b ) {
384
+ return 1 ;
385
+ }
386
+
387
+ return 0 ;
388
+ }
389
+ } ,
351
390
_update_hot_settings : function ( ) {
352
391
this . hot . updateSettings ( this . _hot_settings ( ) ) ;
353
392
} ,
@@ -401,7 +440,7 @@ let SheetView = widgets.DOMWidgetView.extend({
401
440
this . model . save_changes ( ) ;
402
441
} ,
403
442
_on_change : function ( changes , source ) {
404
- if ( this . hot === undefined || source == 'loadData' ) {
443
+ if ( this . hot === undefined || source == 'loadData' || source == 'ObserveChanges.change' ) {
405
444
return ;
406
445
}
407
446
if ( source == 'alter' ) {
0 commit comments