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

Commit fe16cfb

Browse files
committed
Merge pull request #494 from uglymunky/subclassing-grid-columns
[fix #486] inherit columns from Constructor
2 parents be1d986 + 2c30b05 commit fe16cfb

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/backgrid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,7 @@ var Grid = Backgrid.Grid = Backbone.View.extend({
27612761
// Convert the list of column objects here first so the subviews don't have
27622762
// to.
27632763
if (!(options.columns instanceof Backbone.Collection)) {
2764-
options.columns = new Columns(options.columns);
2764+
options.columns = new Columns(options.columns || this.columns);
27652765
}
27662766
this.columns = options.columns;
27672767

src/grid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var Grid = Backgrid.Grid = Backbone.View.extend({
8585
// Convert the list of column objects here first so the subviews don't have
8686
// to.
8787
if (!(options.columns instanceof Backbone.Collection)) {
88-
options.columns = new Columns(options.columns);
88+
options.columns = new Columns(options.columns || this.columns);
8989
}
9090
this.columns = options.columns;
9191

test/grid.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,20 @@ describe("A Grid", function () {
140140
expect($(tbody).find("tr:nth-child(3) > td.integer-cell.editable.sortable.renderable").text()).toBe("3");
141141
});
142142

143+
it("will inherit the constructor's columns", function () {
144+
var columns = [{
145+
name: "title",
146+
cell: "string"
147+
}];
148+
149+
var CustomGrid = Backgrid.Grid.extend({
150+
columns: columns
151+
, className: 'backgrid customBackgrid'
152+
});
153+
154+
var customGrid = new CustomGrid({collection: books});
155+
156+
expect(customGrid.columns.models.length).toBe(1);
157+
expect(customGrid.columns.at(0).get("name")).toBe("title");
158+
});
143159
});

0 commit comments

Comments
 (0)