Skip to content

Fix #1595 row_header sometimes not adding correctly #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ angular.module('ui.grid')
*/
self.api.registerMethod( 'core', 'refreshRows', this.refreshRows );

/**
* @ngdoc function
* @name handleWindowResize
* @methodOf ui.grid.core.api:PublicApi
* @description Trigger a grid resize, normally this would be picked
* up by a watch on window size, but in some circumstances it is necessary
* to call this manually
* @returns {promise} promise that is resolved when render completes?
*
*/
self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize );


/**
* @ngdoc function
Expand Down Expand Up @@ -297,11 +309,18 @@ angular.module('ui.grid')
rowHeaderCol.renderContainer = 'left';
}

self.columnBuilders[0](colDef,rowHeaderCol,self.gridOptions)
// relies on the default column builder being first in array, as it is instantiated
// as part of grid creation
self.columnBuilders[0](colDef,rowHeaderCol,self.options)
.then(function(){
rowHeaderCol.enableFiltering = false;
rowHeaderCol.enableSorting = false;
self.rowHeaderColumns.push(rowHeaderCol);
self.buildColumns()
.then( function() {
self.preCompileCellTemplates();
self.handleWindowResize();
});
});
};

Expand All @@ -319,12 +338,6 @@ angular.module('ui.grid')
var builderPromises = [];
var offset = self.rowHeaderColumns.length;

//add row header columns to the grid columns array
angular.forEach(self.rowHeaderColumns, function (rowHeaderColumn) {
offset++;
self.columns.push(rowHeaderColumn);
});

// Synchronize self.columns with self.options.columnDefs so that columns can also be removed.
if (self.columns.length > self.options.columnDefs.length) {
self.columns.forEach(function (column, index) {
Expand All @@ -334,6 +347,13 @@ angular.module('ui.grid')
});
}

//add row header columns to the grid columns array _after_ columns without columnDefs have been removed
angular.forEach(self.rowHeaderColumns, function (rowHeaderColumn) {
offset++;
self.columns.unshift(rowHeaderColumn);
});


self.options.columnDefs.forEach(function (colDef, index) {
self.preprocessColDef(colDef);
var col = self.getColumn(colDef.name);
Expand Down
1 change: 1 addition & 0 deletions src/js/core/factories/GridColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ angular.module('ui.grid')

//use field if it is defined; name if it is not
self.field = (colDef.field === undefined) ? colDef.name : colDef.field;
self.name = colDef.name;

// Use colDef.displayName as long as it's not undefined, otherwise default to the field name
self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
Expand Down
7 changes: 6 additions & 1 deletion test/unit/core/factories/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ describe('Grid factory', function () {


it('should create left container for left row header', inject(function(gridClassFactory, $timeout) {

var colDefs = [
{name:'col1'}
];
var grid = new gridClassFactory.createGrid({ columnDefs:colDefs });

spyOn( grid, "preCompileCellTemplates").andCallFake(function() {});
spyOn( grid, "handleWindowResize").andCallFake(function() {});

$timeout(function () {
grid.addRowHeaderColumn({name: 'rowHeader', cellTemplate: "<div/>"});
});
Expand All @@ -348,6 +350,9 @@ describe('Grid factory', function () {
var grid = new gridClassFactory.createGrid({columnDefs:colDefs });
grid.rtl = true;

spyOn( grid, "preCompileCellTemplates").andCallFake(function() {});
spyOn( grid, "handleWindowResize").andCallFake(function() {});

$timeout(function () {
grid.addRowHeaderColumn({name: 'rowHeader', cellTemplate: "<div/>"});
});
Expand Down