@@ -83,6 +83,30 @@ function serialize_data(data: DataSource, manager: any): any {
8383
8484function deserialize_data ( data : any , manager : any ) : DataSource {
8585 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+
86110 for ( const column of Object . keys ( data . data ) ) {
87111 deserialized_data [ column ] = [ ] ;
88112
@@ -467,7 +491,10 @@ export class DataGridView extends DOMWidgetView {
467491 } ) ;
468492
469493 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+ ) {
471498 const index = this . model . get ( 'horizontal_stripes' )
472499 ? 'rowBackgroundColor'
473500 : 'columnBackgroundColor' ;
0 commit comments