Skip to content

Commit

Permalink
Merge pull request #101 from martinRenou/fix_none_update
Browse files Browse the repository at this point in the history
Fix setting a cell to None
  • Loading branch information
martinRenou committed Apr 9, 2019
2 parents 5065a59 + 95f891b commit a7f2018
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/src/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
initialize : function () {
SheetModel.__super__.initialize.apply(this, arguments);
this.data = [[]];
this.update_data_grid();
this.update_data_grid(false);
this._updating_grid = false;
this.on('change:rows change:columns', this.update_data_grid, this);
this.on('change:cells', this.on_change_cells, this);
Expand Down Expand Up @@ -100,6 +100,9 @@ let SheetModel = widgets.DOMWidgetModel.extend({
});
},
cells_to_grid: function() {
this.data = [[]];
this.update_data_grid(false);

each(this.get('cells'), (cell) => {
this._cell_data_to_grid(cell)
});
Expand Down Expand Up @@ -195,7 +198,7 @@ let SheetModel = widgets.DOMWidgetModel.extend({
this._updating_grid = false;
}
},
update_data_grid: function() {
update_data_grid: function(trigger_change_event=true) {
// create a row x column array of arrays filled with null
let rows = this.get('rows');
let columns = this.get('columns');
Expand Down Expand Up @@ -224,7 +227,9 @@ let SheetModel = widgets.DOMWidgetModel.extend({
}
this.data[i] = row;
}
this.trigger('data_change');
if (trigger_change_event) {
this.trigger('data_change');
}
}
}, {
serializers: extend({
Expand Down
8 changes: 8 additions & 0 deletions js/src/test/test_sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ describe('sheet', function() {
var data = this.sheet.data;
expect(data[1][2].value, 'for initial value').to.equal(0);
})
it('none cell with should be set', async function() {
var cell = await make_cell.apply(this, [{value: 0.00, type:'numeric'}]);
var data = this.sheet.data;
expect(data[1][2].value, 'for initial value').to.equal(0);
cell.set('value', null);
var data = this.sheet.data;
expect(data[1][2].value, 'for new value').to.equal(null);
})
it('multiple cells added', async function() {
var cell1 = await make_cell.apply(this, [{value: 777}, true])
var cell2 = await make_cell.apply(this, [{row_start: 0, row_end:0, value: 555}, true])
Expand Down

0 comments on commit a7f2018

Please sign in to comment.