Skip to content

Commit a7f2018

Browse files
authored
Merge pull request #101 from martinRenou/fix_none_update
Fix setting a cell to None
2 parents 5065a59 + 95f891b commit a7f2018

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

js/src/sheet.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
6868
initialize : function () {
6969
SheetModel.__super__.initialize.apply(this, arguments);
7070
this.data = [[]];
71-
this.update_data_grid();
71+
this.update_data_grid(false);
7272
this._updating_grid = false;
7373
this.on('change:rows change:columns', this.update_data_grid, this);
7474
this.on('change:cells', this.on_change_cells, this);
@@ -100,6 +100,9 @@ let SheetModel = widgets.DOMWidgetModel.extend({
100100
});
101101
},
102102
cells_to_grid: function() {
103+
this.data = [[]];
104+
this.update_data_grid(false);
105+
103106
each(this.get('cells'), (cell) => {
104107
this._cell_data_to_grid(cell)
105108
});
@@ -195,7 +198,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
195198
this._updating_grid = false;
196199
}
197200
},
198-
update_data_grid: function() {
201+
update_data_grid: function(trigger_change_event=true) {
199202
// create a row x column array of arrays filled with null
200203
let rows = this.get('rows');
201204
let columns = this.get('columns');
@@ -224,7 +227,9 @@ let SheetModel = widgets.DOMWidgetModel.extend({
224227
}
225228
this.data[i] = row;
226229
}
227-
this.trigger('data_change');
230+
if (trigger_change_event) {
231+
this.trigger('data_change');
232+
}
228233
}
229234
}, {
230235
serializers: extend({

js/src/test/test_sheet.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ describe('sheet', function() {
151151
var data = this.sheet.data;
152152
expect(data[1][2].value, 'for initial value').to.equal(0);
153153
})
154+
it('none cell with should be set', async function() {
155+
var cell = await make_cell.apply(this, [{value: 0.00, type:'numeric'}]);
156+
var data = this.sheet.data;
157+
expect(data[1][2].value, 'for initial value').to.equal(0);
158+
cell.set('value', null);
159+
var data = this.sheet.data;
160+
expect(data[1][2].value, 'for new value').to.equal(null);
161+
})
154162
it('multiple cells added', async function() {
155163
var cell1 = await make_cell.apply(this, [{value: 777}, true])
156164
var cell2 = await make_cell.apply(this, [{row_start: 0, row_end:0, value: 555}, true])

0 commit comments

Comments
 (0)