@@ -83,6 +83,30 @@ function serialize_data(data: DataSource, manager: any): any {
83
83
84
84
function deserialize_data ( data : any , manager : any ) : DataSource {
85
85
const deserialized_data : any = { } ;
86
+
87
+ // Backward compatibility for when data.data was an array of rows
88
+ // (should be removed in ipydatagrid 2.x?)
89
+ if ( Array . isArray ( data . data ) ) {
90
+ if ( data . data . length === 0 ) {
91
+ return new DataSource ( deserialized_data , data . fields , data . schema , true ) ;
92
+ }
93
+
94
+ const unpacked = unpack_raw_data ( data . data ) ;
95
+ // Turn array of rows (old approach) into a dictionary of columns as arrays (new approach)
96
+ for ( const column of Object . keys ( unpacked [ 0 ] ) ) {
97
+ const columnData = new Array ( unpacked . length ) ;
98
+ let rowIdx = 0 ;
99
+
100
+ for ( const row of unpacked ) {
101
+ columnData [ rowIdx ++ ] = row [ column ] ;
102
+ }
103
+
104
+ deserialized_data [ column ] = columnData ;
105
+ }
106
+
107
+ return new DataSource ( deserialized_data , data . fields , data . schema , true ) ;
108
+ }
109
+
86
110
for ( const column of Object . keys ( data . data ) ) {
87
111
deserialized_data [ column ] = [ ] ;
88
112
@@ -467,7 +491,10 @@ export class DataGridView extends DOMWidgetView {
467
491
} ) ;
468
492
469
493
const grid_style = this . model . get ( 'grid_style' ) ;
470
- if ( this . model . get ( 'horizontal_stripes' ) || this . model . get ( 'vertical_stripes' ) ) {
494
+ if (
495
+ this . model . get ( 'horizontal_stripes' ) ||
496
+ this . model . get ( 'vertical_stripes' )
497
+ ) {
471
498
const index = this . model . get ( 'horizontal_stripes' )
472
499
? 'rowBackgroundColor'
473
500
: 'columnBackgroundColor' ;
0 commit comments