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 @@ -59,6 +59,7 @@ 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+
6263 this . listenTo ( this . columns , "add remove" , this . updateEmptyRow ) ;
6364 } ,
6465
Original file line number Diff line number Diff line change @@ -224,6 +224,23 @@ describe("A Body", function () {
224224 expect ( body . $el . find ( "tr.empty > td" ) . attr ( "colspan" ) ) . toBe ( "1" ) ;
225225 } ) ;
226226
227+ it ( "will update the colspan of the empty row as columns are changed" , function ( ) {
228+ col . reset ( ) ;
229+ body = new Backgrid . Body ( {
230+ emptyText : " " ,
231+ columns : [ {
232+ name : "id" ,
233+ cell : "integer"
234+ } ] ,
235+ collection : col
236+ } ) ;
237+ body . render ( ) ;
238+
239+ expect ( body . $el . find ( "tr.empty > td" ) . attr ( "colspan" ) ) . toBe ( "1" ) ;
240+ body . columns . push ( { name : "age" , cell : "integer" } ) ;
241+ expect ( body . $el . find ( "tr.empty > td" ) . attr ( "colspan" ) ) . toBe ( "2" ) ;
242+ } ) ;
243+
227244 it ( "will clear the empty row if a new model is added to an empty collection" , function ( ) {
228245 col . reset ( ) ;
229246 body = new Backgrid . Body ( {
@@ -270,6 +287,13 @@ describe("A Body", function () {
270287 expect ( body . $el . find ( "tr.empty" ) . length ) . toBe ( 1 ) ;
271288 } ) ;
272289
290+ it ( "won't call render from updateEmptyRow if there is no emptyView" , function ( ) {
291+ var pushColumn = function ( ) {
292+ body . columns . push ( { name : "age" , cell : "integer" } ) ;
293+ } ;
294+ expect ( pushColumn ) . not . toThrow ( ) ;
295+ } ) ;
296+
273297 it ( "#sort will throw a RangeError is direction is not ascending, descending or null" , function ( ) {
274298 body = new Backgrid . Body ( {
275299 collection : col ,
You can’t perform that action at this time.
0 commit comments