-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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?
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'
@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 :) |
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:
