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

Commit f8bce25

Browse files
committed
Merge pull request #478 from marcneuwirth/empty-row
Render empty row if all existing rows are removed
2 parents fe16cfb + c5f55fc commit f8bce25

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ John Moses <moses.john.r@gmail.com>
2525
Ian Lim <mallim.ink@gmail.com>
2626
David Burrows <david@imergent.com>
2727
Anthony Wu <wu@learnsprout.com>
28+
Marc Neuwirth <marc.neuwirth@gmail.com>

src/body.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var Body = Backgrid.Body = Backbone.View.extend({
6767
emptyText: this.emptyText,
6868
columns: this.columns
6969
}));
70+
return true;
7071
}
7172
},
7273

@@ -154,7 +155,9 @@ var Body = Backgrid.Body = Backbone.View.extend({
154155
// removeRow() is called directly
155156
if (!options) {
156157
this.collection.remove(model, (options = collection));
157-
this._unshiftEmptyRowMayBe();
158+
if (this._unshiftEmptyRowMayBe()) {
159+
this.render();
160+
}
158161
return;
159162
}
160163

@@ -163,7 +166,9 @@ var Body = Backgrid.Body = Backbone.View.extend({
163166
}
164167

165168
this.rows.splice(options.index, 1);
166-
this._unshiftEmptyRowMayBe();
169+
if (this._unshiftEmptyRowMayBe()) {
170+
this.render();
171+
}
167172

168173
return this;
169174
},

test/body.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,29 @@ describe("A Body", function () {
247247
expect(body.$el.find("tr.empty").length).toBe(0);
248248
});
249249

250+
it("will show the empty row if all rows are removed from the collection", function () {
251+
col.reset({id: 4});
252+
body = new Backgrid.Body({
253+
emptyText: " ",
254+
columns: [{
255+
name: "id",
256+
cell: "integer"
257+
}],
258+
collection: col
259+
});
260+
body.render();
261+
expect(body.$el.find("tr.empty").length).toBe(0);
262+
263+
col.remove(col.at(0));
264+
expect(body.$el.find("tr.empty").length).toBe(1);
265+
266+
body.insertRow({id: 5});
267+
expect(body.$el.find("tr.empty").length).toBe(0);
268+
269+
body.removeRow(col.at(0));
270+
expect(body.$el.find("tr.empty").length).toBe(1);
271+
});
272+
250273
it("#sort will throw a RangeError is direction is not ascending, descending or null", function () {
251274
body = new Backgrid.Body({
252275
collection: col,

0 commit comments

Comments
 (0)