@@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel {
36
36
_view_name : 'QgridView' ,
37
37
_model_module : 'qgrid' ,
38
38
_view_module : 'qgrid' ,
39
- _model_module_version : '^1.0.6 -beta.6 ' ,
40
- _view_module_version : '^1.0.6 -beta.6 ' ,
39
+ _model_module_version : '^1.1.0 -beta.0 ' ,
40
+ _view_module_version : '^1.1.0 -beta.0 ' ,
41
41
_df_json : '' ,
42
42
_columns : { }
43
43
} ) ;
@@ -215,6 +215,9 @@ class QgridView extends widgets.DOMWidgetView {
215
215
this . sort_in_progress = false ;
216
216
this . sort_indicator = null ;
217
217
this . resizing_column = false ;
218
+ this . ignore_selection_changed = false ;
219
+ this . vp_response_expected = false ;
220
+ this . next_viewport_msg = null ;
218
221
219
222
var number_type_info = {
220
223
filter : slider_filter . SliderFilter ,
@@ -318,14 +321,7 @@ class QgridView extends widgets.DOMWidgetView {
318
321
319
322
var type_info = this . type_infos [ cur_column . type ] || { } ;
320
323
321
- var slick_column = {
322
- name : cur_column . name ,
323
- field : cur_column . name ,
324
- id : cur_column . name ,
325
- sortable : false ,
326
- resizable : true ,
327
- cssClass : cur_column . type
328
- } ;
324
+ var slick_column = cur_column ;
329
325
330
326
Object . assign ( slick_column , type_info ) ;
331
327
@@ -345,9 +341,18 @@ class QgridView extends widgets.DOMWidgetView {
345
341
this . filter_list . push ( cur_filter ) ;
346
342
}
347
343
344
+ if ( cur_column . width == null ) {
345
+ delete slick_column . width ;
346
+ }
347
+
348
+ if ( cur_column . maxWidth == null ) {
349
+ delete slick_column . maxWidth ;
350
+ }
351
+
348
352
// don't allow editing index columns
349
353
if ( cur_column . is_index ) {
350
354
slick_column . editor = editors . IndexEditor ;
355
+
351
356
slick_column . cssClass += ' idx-col' ;
352
357
if ( cur_column . first_index ) {
353
358
slick_column . cssClass += ' first-idx-col' ;
@@ -358,9 +363,19 @@ class QgridView extends widgets.DOMWidgetView {
358
363
359
364
slick_column . name = cur_column . index_display_text ;
360
365
slick_column . level = cur_column . level ;
366
+
367
+ if ( this . grid_options . boldIndex ) {
368
+ slick_column . cssClass += ' idx-col' ;
369
+ }
370
+
361
371
this . index_columns . push ( slick_column ) ;
362
372
continue ;
363
373
}
374
+
375
+ if ( cur_column . editable == false ) {
376
+ slick_column . editor = null ;
377
+ }
378
+
364
379
this . columns . push ( slick_column ) ;
365
380
}
366
381
@@ -431,19 +446,28 @@ class QgridView extends widgets.DOMWidgetView {
431
446
if ( this . sort_in_progress ) {
432
447
return ;
433
448
}
434
- this . sort_in_progress = true ;
435
449
436
450
var col_header = $ ( e . target ) . closest ( ".slick-header-column" ) ;
437
451
if ( ! col_header . length ) {
438
452
return ;
439
453
}
440
454
441
455
var column = col_header . data ( "column" ) ;
456
+ if ( column . sortable == false ) {
457
+ return ;
458
+ }
459
+
460
+ this . sort_in_progress = true ;
461
+
442
462
if ( this . sorted_column == column ) {
443
463
this . sort_ascending = ! this . sort_ascending ;
444
464
} else {
445
465
this . sorted_column = column ;
446
- this . sort_ascending = true ;
466
+ if ( 'defaultSortAsc' in column ) {
467
+ this . sort_ascending = column . defaultSortAsc ;
468
+ } else {
469
+ this . sort_ascending = true ;
470
+ }
447
471
}
448
472
449
473
var all_classes = 'fa-sort-asc fa-sort-desc fa fa-spin fa-spinner' ;
@@ -458,7 +482,7 @@ class QgridView extends widgets.DOMWidgetView {
458
482
this . grid_elem . find ( '.slick-sort-indicator' ) . removeClass ( all_classes ) ;
459
483
this . sort_indicator . addClass ( `fa fa-spinner fa-spin` ) ;
460
484
var msg = {
461
- 'type' : 'sort_changed ' ,
485
+ 'type' : 'change_sort ' ,
462
486
'sort_field' : this . sorted_column . field ,
463
487
'sort_ascending' : this . sort_ascending
464
488
} ;
@@ -475,29 +499,48 @@ class QgridView extends widgets.DOMWidgetView {
475
499
}
476
500
this . viewport_timeout = setTimeout ( ( ) => {
477
501
this . last_vp = this . slick_grid . getViewport ( ) ;
478
- var msg = {
479
- 'type' : 'viewport_changed' ,
480
- 'top' : this . last_vp . top ,
481
- 'bottom' : this . last_vp . bottom
482
- } ;
483
- this . send ( msg ) ;
502
+ var cur_range = this . model . get ( '_viewport_range' ) ;
503
+
504
+ if ( this . last_vp . top != cur_range [ 0 ] || this . last_vp . bottom != cur_range [ 1 ] ) {
505
+ var msg = {
506
+ 'type' : 'change_viewport' ,
507
+ 'top' : this . last_vp . top ,
508
+ 'bottom' : this . last_vp . bottom
509
+ } ;
510
+ if ( this . vp_response_expected ) {
511
+ this . next_viewport_msg = msg
512
+ } else {
513
+ this . vp_response_expected = true ;
514
+ this . send ( msg ) ;
515
+ }
516
+ }
484
517
this . viewport_timeout = null ;
485
- } , 10 ) ;
518
+ } , 100 ) ;
486
519
} ) ;
487
520
488
521
// set up callbacks
522
+ let editable_rows = this . model . get ( '_editable_rows' ) ;
523
+ if ( editable_rows && Object . keys ( editable_rows ) . length > 0 ) {
524
+ this . slick_grid . onBeforeEditCell . subscribe ( ( e , args ) => {
525
+ editable_rows = this . model . get ( '_editable_rows' ) ;
526
+ return editable_rows [ args . item [ this . index_col_name ] ]
527
+ } ) ;
528
+ }
529
+
489
530
this . slick_grid . onCellChange . subscribe ( ( e , args ) => {
490
531
var column = this . columns [ args . cell ] . name ;
491
532
var data_item = this . slick_grid . getDataItem ( args . row ) ;
492
533
var msg = { 'row_index' : data_item . row_index , 'column' : column ,
493
534
'unfiltered_index' : data_item [ this . index_col_name ] ,
494
- 'value' : args . item [ column ] , 'type' : 'cell_change ' } ;
535
+ 'value' : args . item [ column ] , 'type' : 'edit_cell ' } ;
495
536
this . send ( msg ) ;
496
537
} ) ;
497
538
498
539
this . slick_grid . onSelectedRowsChanged . subscribe ( ( e , args ) => {
499
- var msg = { 'rows' : args . rows , 'type' : 'selection_changed' } ;
500
- this . send ( msg ) ;
540
+ if ( ! this . ignore_selection_changed ) {
541
+ var msg = { 'rows' : args . rows , 'type' : 'change_selection' } ;
542
+ this . send ( msg ) ;
543
+ }
501
544
} ) ;
502
545
503
546
setTimeout ( ( ) => {
@@ -648,7 +691,17 @@ class QgridView extends widgets.DOMWidgetView {
648
691
this . multi_index = this . model . get ( "_multi_index" ) ;
649
692
var data_view = this . create_data_view ( df_json . data ) ;
650
693
651
- if ( msg . triggered_by == 'sort_changed' && this . sort_indicator ) {
694
+ if ( msg . triggered_by === 'change_viewport' ) {
695
+ if ( this . next_viewport_msg ) {
696
+ this . send ( this . next_viewport_msg ) ;
697
+ this . next_viewport_msg = null ;
698
+ return ;
699
+ } else {
700
+ this . vp_response_expected = false ;
701
+ }
702
+ }
703
+
704
+ if ( msg . triggered_by == 'change_sort' && this . sort_indicator ) {
652
705
var asc = this . model . get ( '_sort_ascending' ) ;
653
706
this . sort_indicator . removeClass (
654
707
'fa-spinner fa-spin fa-sort-asc fa-sort-desc'
@@ -694,7 +747,7 @@ class QgridView extends widgets.DOMWidgetView {
694
747
} else if ( msg . triggered_by === 'add_row' ) {
695
748
this . slick_grid . scrollRowIntoView ( msg . scroll_to_row ) ;
696
749
this . slick_grid . setSelectedRows ( [ msg . scroll_to_row ] ) ;
697
- } else if ( msg . triggered_by === 'viewport_changed ' &&
750
+ } else if ( msg . triggered_by === 'change_viewport ' &&
698
751
this . last_vp . bottom >= this . df_length ) {
699
752
this . slick_grid . scrollRowIntoView ( this . last_vp . bottom ) ;
700
753
}
@@ -704,9 +757,22 @@ class QgridView extends widgets.DOMWidgetView {
704
757
} ) ;
705
758
this . send ( {
706
759
'rows' : selected_rows ,
707
- 'type' : 'selection_changed '
760
+ 'type' : 'change_selection '
708
761
} ) ;
709
- } , 10 ) ;
762
+ } , 100 ) ;
763
+ } else if ( msg . type == 'toggle_editable' ) {
764
+ if ( this . slick_grid . getOptions ( ) . editable == false ) {
765
+ this . slick_grid . setOptions ( { 'editable' : true } ) ;
766
+ } else {
767
+ this . slick_grid . setOptions ( { 'editable' : false } ) ;
768
+ }
769
+ } else if ( msg . type == 'change_selection' ) {
770
+ this . ignore_selection_changed = true ;
771
+ this . slick_grid . setSelectedRows ( msg . rows ) ;
772
+ if ( msg . rows && msg . rows . length > 0 ) {
773
+ this . slick_grid . scrollRowIntoView ( msg . rows [ 0 ] ) ;
774
+ }
775
+ this . ignore_selection_changed = false ;
710
776
} else if ( msg . col_info ) {
711
777
var filter = this . filters [ msg . col_info . name ] ;
712
778
filter . handle_msg ( msg ) ;
0 commit comments