@@ -49,15 +49,40 @@ export default class Home extends React.Component {
49
49
hideRow : this . onChange ,
50
50
deleteColumn : this . onChange ,
51
51
deleteRow : this . onChange ,
52
- insertColumn : ( ) => {
53
- var workbook = this . getJSON ( ) ;
52
+ insertColumn : ( event ) => {
53
+ let workbook = this . getJSON ( ) ;
54
54
workbook . columns = ++ this . numColumns ;
55
+
56
+ let sheet = workbook . sheets . find ( e => e . name === workbook . activeSheet ) ;
57
+
58
+ // for every row in this sheet data
59
+ // iterate over all of each rows' cells and add 1
60
+ // KendoUI provides the correct index corresponding to add 'left' or 'right'
61
+ sheet . rows . forEach ( row => {
62
+ row . cells . forEach ( cell => {
63
+ if ( cell . index >= event . index ) {
64
+ cell . index += 1 ;
65
+ }
66
+ } ) ;
67
+ } ) ;
68
+
55
69
this . getSpreadsheet ( ) . fromJSON ( workbook ) ;
56
70
this . onChange ( ) ;
57
71
} ,
58
72
insertRow : ( event ) => {
59
- var workbook = this . getJSON ( ) ;
73
+ let workbook = this . getJSON ( ) ;
60
74
workbook . rows = ++ this . numRows ;
75
+
76
+ let sheet = workbook . sheets . find ( e => e . name === workbook . activeSheet ) ;
77
+
78
+ // iterate over each row and add 1 to the index
79
+ // KendoUI provides the correct index corresponding to add 'above' or 'below'
80
+ sheet . rows . forEach ( row => {
81
+ if ( row . index >= event . index ) {
82
+ row . index += 1 ;
83
+ }
84
+ } ) ;
85
+
61
86
this . getSpreadsheet ( ) . fromJSON ( workbook ) ;
62
87
this . onChange ( ) ;
63
88
}
0 commit comments