Skip to content

Feature - Empty Base Layer #5687

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 2 commits into from
Oct 19, 2016
Merged

Feature - Empty Base Layer #5687

merged 2 commits into from
Oct 19, 2016

Conversation

louwie17
Copy link

This pull request adds a new feature 'emptyBaseLayer', that provides a background for the ui-grid, of continues rows, incase the height of the ui-grid is greater then the number of rows displayed.
This simulates a similar scenario as Excel, where the rows continue forever. The only exception is that the rows can't be edited, and just act as a background.
The rows/columns work with column resizing, and pinned rows.

A new tutorial page has been added. This is what it looks like in the tutorial:
emptybaselayer

Copy link
Member

@mportuga mportuga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments in the code review. Also, it would be helpful if you squashed your commits into one and followed our practices for commit comments so that your changes can show up in the change log. Personally I suggest using commitzen.
https://github.com/angular-ui/ui-grid/blob/master/CONTRIBUTING.md#-git-commit-guidelines

* @description Enable empty base layer, which shows empty rows as background on the entire grid
* <br/>Defaults to true, if the directive is used.
*/
grid.options.enableEmptyGridBaseLayer = grid.options.enableEmptyGridBaseLayer !== false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this just overwrite the line above? (line 35 to be exact)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the two lines are different, I wanted to give the option of passing in true/false into the uiGridEmptyBaseLayer directive, like this: ui-grid-empty-base-layer="true/false". I wanted that to trump the grid.options value. That's why I check that before hand.
Unless you have a different suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I can't think of another suggestion right now, but perhaps one of the other devs will.


$scope.randomSize = function () {
var newHeight = Math.floor(Math.random() * (300 - 100 + 1) + 300);
var newWidth = Math.floor(Math.random() * (600 - 200 + 1) + 200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to use var here, you can use a comma to separate this line and the one above.

* @name ui.grid.emptyBaseLayer.api:GridOptions
*
* @description GridOptions for emptyBaseLayer feature, these are available to be
* set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment block be put above the grid.baseLayer object declaration?


setNumberOfEmptyRows: function(viewportHeight, grid) {
var rowHeight = grid.options.rowHeight;
var rows = Math.ceil(viewportHeight / rowHeight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to use var here, you can use a comma to separate this line and the one above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make that change!

}

var renderBodyContainer = uiGridCtrl.grid.renderContainers.body;
var prevGridHeight = renderBodyContainer.getViewportHeight();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to use var here, you can use a comma to separate this line and the one above.

var emptyBaseLayerContainer = $templateCache.get('ui-grid/emptyBaseLayerContainer');
$elm.prepend(emptyBaseLayerContainer);
return {
pre: function ($scope, $elm, $attrs, controllers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

angular.noop might make more sense here since this function doesn't do anything.

return {
pre: function ($scope, $elm, $attrs, controllers) {
},
post: function ($scope, $elm, $attrs, controllers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

angular.noop might make more sense here since this function doesn't do anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this as it seemed to be the standard for the other features, mostly looked at https://github.com/angular-ui/ui-grid/blob/master/src/features/expandable/js/expandable.js#L531

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I guess this should stay this way then.


.ui-grid-viewport .ui-grid-empty-base-layer-container {
position: absolute;
height: 100% !important;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this important here? That could cause a lot for problems to users of ui-grid that are overwriting the default styles. Can this be done some other way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for using is because the same div inherits from 'ui-grid-canvas' as well, which gets a dynamic height/width, but I always wanted this div to take the full height of the viewport. So I should be able to find a different way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thanks!


var $compile = _$compile_;
scope = $rootScope;
timeout = $timeout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this timeout variable really needed? It does not get used anywhere. Even $timeout itself is only used inside this beforeEach function.

$timeout(function () {
$compile(element)(scope);
});
$timeout.flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you wrapping the compilation in a timeout? You could just as easily add a scope.$apply() function call after compiling the element instead of adding a timeout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the only reason for doing this was going of these tests: https://github.com/angular-ui/ui-grid/blob/master/src/features/expandable/test/expandable.spec.js#L29

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to fix those later in that case. But in the meantime there is no reason that new code should follow the same bad practice.

emptyRows: []
};

grid.options.enableEmptyGridBaseLayer = baseLayerAttr !== "false";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined and null are both different than "false" couldn't that cause a problem? Is there a way for you to ensure that baseLayerAttr is a boolean when it comes in instead of a string?

Lourens Schep added 2 commits September 22, 2016 09:06
background

Made a new feature called 'emptyBaseLayer'. This can be added to the
ui-grid by using ui-grid-empty-base-layer. This creates a fake
background for the ui-grid of continues rows, the rows are not editable
or clickable, and just act as a background.
There also is a new tutorial page '218 Empty Base Layer'
@louwie17
Copy link
Author

@mportuga I updated your suggested changes, see what you think? Also I squashed all the commits, hopefully that looks a little better. It was my first time doing that actually, so I had some fun screwing up the rebasing here and there :)

@dlgski dlgski added breaking and removed breaking labels Oct 19, 2016
@dlgski dlgski merged commit 9397359 into angular-ui:master Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants