Skip to content

Commit e9c7857

Browse files
committed
Working solution for adding rows and columns at the expected location
1 parent c15fb05 commit e9c7857

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

app/components/Home.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,40 @@ export default class Home extends React.Component {
4949
hideRow: this.onChange,
5050
deleteColumn: this.onChange,
5151
deleteRow: this.onChange,
52-
insertColumn: () => {
53-
var workbook = this.getJSON();
52+
insertColumn: (event) => {
53+
let workbook = this.getJSON();
5454
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+
5569
this.getSpreadsheet().fromJSON(workbook);
5670
this.onChange();
5771
},
5872
insertRow: (event) => {
59-
var workbook = this.getJSON();
73+
let workbook = this.getJSON();
6074
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+
6186
this.getSpreadsheet().fromJSON(workbook);
6287
this.onChange();
6388
}

0 commit comments

Comments
 (0)