This repository was archived by the owner on Apr 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments