Permalink
Browse files

handle case where grid is shown w/o rows

fixes DAQ-652
  • Loading branch information...
1 parent 4475ed1 commit 4a4b24621b4d9b2eee4a85bf2e0af77a90099033 @aaronj1335 aaronj1335 committed Feb 11, 2013
Showing with 29 additions and 4 deletions.
  1. +6 −4 src/widgets/powergrid.js
  2. +23 −0 src/widgets/powergrid/test.js
View
@@ -449,14 +449,16 @@ define([
},
show: function() {
- var self = this;
+ var self = this, models;
self._super.apply(this, arguments);
this.spinner.instantiate();
this._setScrollTop();
// post render for columns
- _.each(this.get('columnModel').columns, function(c) {
- c._setThCellWidth();
- });
+ if ((models = this.get('models')) && models.length) {
+ _.each(this.get('columnModel').columns, function(c) {
+ c._setThCellWidth();
+ });
+ }
},
update: function(updated) {
@@ -42,6 +42,13 @@ define([
setup = utils.setup,
trim = utils.trim;
+ function aboutEqual(a, b, msg, tolerance) {
+ var greater = a > b? a : b;
+ msg = msg == null? 'values are within ' + tolerance*100 + '%' : msg;
+ tolerance = tolerance || 0.02;
+ ok(Math.abs(a-b) / greater < tolerance, msg);
+ }
+
asyncTest('everythings cool', function() {
setup().then(function(g, options) {
equal(g.get('models').length, options.params.limit);
@@ -650,6 +657,22 @@ define([
});
});
+ asyncTest('showing after resize', function() {
+ setup({appendTo: 'body'}).then(function(g) {
+ var w, c = g.get('collection'), col = g.get('columnModel').columns[0];
+ col.set('width', 400);
+ g.del('collection');
+ Example.mockDelay(500);
+ g.hide();
+ g.show();
+ g.set('collection', Example.collection());
+ w = parseInt(col.el.style.width, 10);
+ ok(_.isNumber(w) && !_.isNaN(w), 'column header width is set to a number');
+ aboutEqual(w, 400, 'column header width is about 400px');
+ start();
+ });
+ });
+
module('hiding columns');
asyncTest('hiding column works', function() {

0 comments on commit 4a4b246

Please sign in to comment.