Skip to content

Commit

Permalink
feat(core): expose GridMenuTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
vwongg authored and mportuga committed Dec 30, 2016
1 parent 138d149 commit 5f15eab
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/js/core/directives/ui-grid-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
templateUrl: 'ui-grid/uiGridMenu',
replace: false,
link: function ($scope, $elm, $attrs, uiGridCtrl) {

$scope.dynamicStyles = '';
if (uiGridCtrl && uiGridCtrl.grid && uiGridCtrl.grid.options && uiGridCtrl.grid.options.gridMenuTemplate) {
var gridMenuTemplate = uiGridCtrl.grid.options.gridMenuTemplate;
gridUtil.getTemplate(gridMenuTemplate).then(function (contents) {
var template = angular.element(contents);
var newElm = $compile(template)($scope);
$elm.replaceWith(newElm);
});
}

var setupHeightStyle = function(gridHeight) {
//menu appears under header row, so substract that height from it's total
Expand All @@ -61,7 +68,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
setupHeightStyle(uiGridCtrl.grid.gridHeight);
uiGridCtrl.grid.api.core.on.gridDimensionChanged($scope, function(oldGridHeight, oldGridWidth, newGridHeight, newGridWidth) {
setupHeightStyle(newGridHeight);
});
});
}

$scope.i18n = {
Expand Down
9 changes: 9 additions & 0 deletions src/js/core/factories/GridOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,15 @@ angular.module('ui.grid')
*/
baseOptions.rowTemplate = baseOptions.rowTemplate || 'ui-grid/ui-grid-row';

/**
* @ngdoc string
* @name gridMenuTemplate
* @propertyOf ui.grid.class:GridOptions
* @description 'ui-grid/uiGridMenu' by default. When provided, this setting uses a
* custom grid menu template.
*/
baseOptions.gridMenuTemplate = baseOptions.gridMenuTemplate || 'ui-grid/uiGridMenu';

/**
* @ngdoc object
* @name appScopeProvider
Expand Down
29 changes: 29 additions & 0 deletions test/unit/core/directives/ui-grid-menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,33 @@ describe('ui-grid-menu', function() {
expect(hideSpy).toHaveBeenCalled();
});
});

describe('custom gridMenu templates', function () {
var $timeout;
var customGridMenu = '<div ui-grid-menu-custom menu-items="items"></div>';

beforeEach(inject(function (_$timeout_) {
$timeout = _$timeout_;
}));
beforeEach( function() {
recompile = function () {
var element = angular.element('<div ui-grid="gridOptions"></div>');
$scope.gridOptions = {};
$scope.gridOptions.gridMenuTemplate = customGridMenu;
$scope.gridOptions.onRegisterApi = function(gridApi) {
$scope.grid = gridApi.grid;
};
$timeout(function () {
$compile(element)($scope);
});
$timeout.flush();
};

recompile();
});

it('should have gridMenuTemplate defined in grid options', function() {
expect($scope.grid.options.gridMenuTemplate).toEqual(customGridMenu);
});
});
});
5 changes: 5 additions & 0 deletions test/unit/core/factories/GridOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('GridOptions factory', function () {
footerTemplate: 'ui-grid/ui-grid-footer',
gridFooterTemplate: 'ui-grid/ui-grid-grid-footer',
rowTemplate: 'ui-grid/ui-grid-row',
gridMenuTemplate: 'ui-grid/uiGridMenu',
appScopeProvider: null
});
});
Expand Down Expand Up @@ -96,6 +97,7 @@ describe('GridOptions factory', function () {
footerTemplate: 'testFooter',
gridFooterTemplate: 'testGridFooter',
rowTemplate: 'testRow',
gridMenuTemplate: 'testGridMenu',
extraOption: 'testExtraOption',
appScopeProvider : 'anotherRef'
};
Expand Down Expand Up @@ -139,6 +141,7 @@ describe('GridOptions factory', function () {
footerTemplate: 'testFooter',
gridFooterTemplate: 'testGridFooter',
rowTemplate: 'testRow',
gridMenuTemplate: 'testGridMenu',
extraOption: 'testExtraOption',
appScopeProvider : 'anotherRef'
});
Expand Down Expand Up @@ -185,6 +188,7 @@ describe('GridOptions factory', function () {
footerTemplate: 'testFooter',
gridFooterTemplate: 'testGridFooter',
rowTemplate: 'testRow',
gridMenuTemplate: 'testGridMenu',
extraOption: 'testExtraOption'
};
expect( GridOptions.initialize(options) ).toEqual({
Expand Down Expand Up @@ -227,6 +231,7 @@ describe('GridOptions factory', function () {
footerTemplate: 'testFooter',
gridFooterTemplate: 'testGridFooter',
rowTemplate: 'testRow',
gridMenuTemplate: 'testGridMenu',
extraOption: 'testExtraOption',
appScopeProvider : null
});
Expand Down

0 comments on commit 5f15eab

Please sign in to comment.