Skip to content

Commit 572766d

Browse files
committed
fix(core): add row headers in order
grid.addRowHeader api now takes a 2nd parameter, order, that is used to insert the row header in proper order. For example, the order is now Grouping/Treeview row header, Expandable row header, then Selection row header if you use those features. Also, expandable RowHeader is now hidden for Group summary rows BREAKING CHANGE: It is possible that your application will show row headers in a different order after this change. If you are adding rowHeaders, use the new order parameter in grid.addRowHeader(colDef, order) to specify where you want the header column.
1 parent 2762eda commit 572766d

File tree

8 files changed

+54
-54
lines changed

8 files changed

+54
-54
lines changed

src/features/expandable/js/expandable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
};
336336
expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader');
337337
expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader');
338-
uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef);
338+
uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef, -90);
339339
}
340340
uiGridExpandableService.initializeGrid(uiGridCtrl.grid);
341341
},

src/features/expandable/templates/expandableRowHeader.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class="ui-grid-row-header-cell ui-grid-expandable-buttons-cell">
33
<div
44
class="ui-grid-cell-contents">
5-
<i
5+
<i ng-if="!row.groupHeader==true"
66
ng-class="{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }"
77
ng-click="grid.api.expandable.toggleRowExpansion(row.entity)">
88
</i>

src/features/grouping/js/grouping.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@
619619
columns.sort(function(a, b){
620620
var a_group, b_group;
621621
if (a.isRowHeader){
622-
a_group = -1000;
622+
a_group = a.headerPriority;
623623
}
624624
else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0){
625625
a_group = null;
@@ -628,7 +628,7 @@
628628
}
629629

630630
if (b.isRowHeader){
631-
b_group = -1000;
631+
b_group = b.headerPriority;
632632
}
633633
else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0){
634634
b_group = null;

src/features/grouping/test/grouping.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
8585
it( 'will not move header columns', function() {
8686

8787
$timeout(function () {
88-
grid.addRowHeaderColumn({name:'aRowHeader'});
88+
grid.addRowHeaderColumn({name:'aRowHeader'}, -200);
8989
});
9090
$timeout.flush();
9191

src/features/selection/js/selection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@
667667
allowCellFocus: true
668668
};
669669

670-
uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef);
670+
uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef, 0);
671671
}
672672

673673
var processorSet = false;

src/features/tree-base/js/tree-base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@
461461
* @ngdoc object
462462
* @name showTreeRowHeader
463463
* @propertyOf ui.grid.treeBase.api:GridOptions
464-
* @description If set to false, don't create the row header. Youll need to programatically control the expand
464+
* @description If set to false, don't create the row header. You'll need to programmatically control the expand
465465
* states
466466
* <br/>Defaults to true
467467
*/
@@ -715,7 +715,7 @@
715715
};
716716

717717
rowHeaderColumnDef.visible = grid.options.treeRowHeaderAlwaysVisible;
718-
grid.addRowHeaderColumn( rowHeaderColumnDef );
718+
grid.addRowHeaderColumn( rowHeaderColumnDef, -100 );
719719
},
720720

721721

src/js/core/factories/Grid.js

+36-21
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ angular.module('ui.grid')
272272
* @methodOf ui.grid.core.api:PublicApi
273273
* @description adds a row header column to the grid
274274
* @param {object} column def
275+
* @param {number} order Determines order of header column on grid. Lower order means header
276+
* is positioned to the left of higher order headers
275277
*
276278
*/
277279
self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn );
@@ -379,7 +381,7 @@ angular.module('ui.grid')
379381
* that have sorting on them, sorted in priority order.
380382
*
381383
* @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
382-
* @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
384+
* @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
383385
* columns with sorts on them, in priority order.
384386
*
385387
* @example
@@ -754,8 +756,14 @@ angular.module('ui.grid')
754756
* @description adds a row header column to the grid
755757
* @param {object} column def
756758
*/
757-
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef) {
759+
Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order) {
758760
var self = this;
761+
762+
//default order
763+
if (order === undefined) {
764+
order = 0;
765+
}
766+
759767
var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self);
760768
rowHeaderCol.isRowHeader = true;
761769
if (self.isRTL()) {
@@ -774,7 +782,12 @@ angular.module('ui.grid')
774782
rowHeaderCol.enableFiltering = false;
775783
rowHeaderCol.enableSorting = false;
776784
rowHeaderCol.enableHiding = false;
785+
rowHeaderCol.headerPriority = order;
777786
self.rowHeaderColumns.push(rowHeaderCol);
787+
self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) {
788+
return a.headerPriority - b.headerPriority;
789+
});
790+
778791
self.buildColumns()
779792
.then( function() {
780793
self.preCompileCellTemplates();
@@ -836,9 +849,11 @@ angular.module('ui.grid')
836849
}
837850

838851
//add row header columns to the grid columns array _after_ columns without columnDefs have been removed
839-
self.rowHeaderColumns.forEach(function (rowHeaderColumn) {
840-
self.columns.unshift(rowHeaderColumn);
841-
});
852+
//rowHeaderColumns is ordered by priority so insert in reverse
853+
for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) {
854+
self.columns.unshift(self.rowHeaderColumns[j]);
855+
}
856+
842857

843858

844859
// look at each column def, and update column properties to match. If the column def
@@ -898,6 +913,19 @@ angular.module('ui.grid')
898913
});
899914
};
900915

916+
Grid.prototype.preCompileCellTemplate = function(col) {
917+
var self = this;
918+
var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
919+
html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
920+
921+
var compiledElementFn = $compile(html);
922+
col.compiledElementFn = compiledElementFn;
923+
924+
if (col.compiledElementFnDefer) {
925+
col.compiledElementFnDefer.resolve(col.compiledElementFn);
926+
}
927+
};
928+
901929
/**
902930
* @ngdoc function
903931
* @name preCompileCellTemplates
@@ -906,25 +934,12 @@ angular.module('ui.grid')
906934
*/
907935
Grid.prototype.preCompileCellTemplates = function() {
908936
var self = this;
909-
910-
var preCompileTemplate = function( col ) {
911-
var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
912-
html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
913-
914-
var compiledElementFn = $compile(html);
915-
col.compiledElementFn = compiledElementFn;
916-
917-
if (col.compiledElementFnDefer) {
918-
col.compiledElementFnDefer.resolve(col.compiledElementFn);
919-
}
920-
};
921-
922-
this.columns.forEach(function (col) {
937+
self.columns.forEach(function (col) {
923938
if ( col.cellTemplate ){
924-
preCompileTemplate( col );
939+
self.preCompileCellTemplate( col );
925940
} else if ( col.cellTemplatePromise ){
926941
col.cellTemplatePromise.then( function() {
927-
preCompileTemplate( col );
942+
self.preCompileCellTemplate( col );
928943
});
929944
}
930945
});

test/unit/core/factories/Grid.spec.js

+10-25
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,19 @@ describe('Grid factory', function () {
294294
expect(grid1.columns[5].name).toEqual('5');
295295
});
296296

297-
it('should respect the row header', function() {
297+
it('should respect the row header in order', function() {
298298
var columnDefs = [
299299
{name:'1'},
300-
{name:'2'},
301-
{name:'3'},
302-
{name:'4'},
303-
{name:'5'}
300+
{name:'2'}
304301
];
305302

306303
var grid1 = gridClassFactory.createGrid({columnDefs:columnDefs});
307304

308305

309306
$timeout(function(){
310-
grid1.addRowHeaderColumn({name:'rowHeader'});
307+
grid1.addRowHeaderColumn({name:'rowHeader3'},100);
308+
grid1.addRowHeaderColumn({name:'rowHeader1'},-100);
309+
grid1.addRowHeaderColumn({name:'rowHeader2'},0);
311310
});
312311
$timeout.flush();
313312

@@ -317,26 +316,12 @@ describe('Grid factory', function () {
317316
$timeout.flush();
318317

319318

320-
expect(grid1.columns[0].name).toEqual('rowHeader');
321-
expect(grid1.columns[1].name).toEqual('1');
322-
expect(grid1.columns[2].name).toEqual('2');
323-
expect(grid1.columns[3].name).toEqual('3');
324-
expect(grid1.columns[4].name).toEqual('4');
325-
expect(grid1.columns[5].name).toEqual('5');
319+
expect(grid1.columns[0].name).toEqual('rowHeader1');
320+
expect(grid1.columns[1].name).toEqual('rowHeader2');
321+
expect(grid1.columns[2].name).toEqual('rowHeader3');
322+
expect(grid1.columns[3].name).toEqual('1');
323+
expect(grid1.columns[4].name).toEqual('2');
326324

327-
grid1.options.columnDefs.splice(3, 0, {name: '3.5'});
328-
329-
$timeout(function(){
330-
grid1.buildColumns();
331-
});
332-
$timeout.flush();
333-
334-
expect(grid1.columns[1].name).toEqual('1');
335-
expect(grid1.columns[2].name).toEqual('2');
336-
expect(grid1.columns[3].name).toEqual('3');
337-
expect(grid1.columns[4].name).toEqual('3.5');
338-
expect(grid1.columns[5].name).toEqual('4');
339-
expect(grid1.columns[6].name).toEqual('5');
340325
});
341326

342327
it('add columns at the correct position - start', function() {

0 commit comments

Comments
 (0)