Skip to content
This repository was archived by the owner on Apr 2, 2019. It is now read-only.

Commit 0de1bf7

Browse files
author
Joe
committed
implement EmptyRow dynamic colspan updating
adds an event listener to columns changing such that the EmptyRow re-renders and updates it's colspan
1 parent bba4c3e commit 0de1bf7

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/body.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ var Body = Backgrid.Body = Backbone.View.extend({
5959
this.listenTo(collection, "reset", this.refresh);
6060
this.listenTo(collection, "backgrid:sort", this.sort);
6161
this.listenTo(collection, "backgrid:edited", this.moveToNextCell);
62+
this.listenTo(this.columns, "add remove", this.updateEmptyRow);
6263
},
6364

6465
_unshiftEmptyRowMayBe: function () {
6566
if (this.rows.length === 0 && this.emptyText != null) {
66-
this.rows.unshift(new EmptyRow({
67+
this.emptyRow = new EmptyRow({
6768
emptyText: this.emptyText,
6869
columns: this.columns
69-
}));
70-
return true;
70+
});
71+
72+
this.rows.unshift(this.emptyRow);
73+
return true
7174
}
7275
},
7376

@@ -173,6 +176,17 @@ var Body = Backgrid.Body = Backbone.View.extend({
173176
return this;
174177
},
175178

179+
/**
180+
Rerender the EmptyRow which empties the DOM element, creates the td with the
181+
updated colspan, and appends it back into the DOM
182+
*/
183+
184+
updateEmptyRow: function () {
185+
if (this.emptyRow != null) {
186+
this.emptyRow.render();
187+
}
188+
},
189+
176190
/**
177191
Reinitialize all the rows inside the body and re-render them. Triggers a
178192
Backbone `backgrid:refresh` event from the collection along with the body

0 commit comments

Comments
 (0)