-
Notifications
You must be signed in to change notification settings - Fork 3.4k
md-virtual-repeat does not work without predefined height #4314
Comments
I think md-virtual-repeat-container should have fixed height |
Yup. That was the issue. Perhaps a doc clarification on that point? |
I referred to official doc's sample codes |
+1 Would be nice to figure out a way to allow flexable heights. |
It's on my to-do list. It's tricky because any solution comes with performance trade-offs. |
+1 This tripped me up for a while, a note on the docs would be cool. |
Here's my workaround in the mean time: this.getListHeight = function() {
return {height: '' + ($window.innerHeight - 72) + 'px'};
};
$window.addEventListener('resize', onResize);
function onResize() {
$scope.$digest();
}
$scope.$on('$destroy', function() {
$window.removeEventListener('resize', onResize);
}); Then in the HTML <md-virtual-repeat-container id="vertical-container" ng-style="ctrl.getListHeight()">
...
</md-virtual-repeat-container> |
@colinskow - Thanks, it's close to working, it works for me on refresh, but not on regular state-changes A huge +1 for making virtual-repeat flexable. |
@Madd0g - I actually refactored it a little bit and it seems to work better. At least on Safari and Chrome it always appears to be the right size. this.listStyle = {
height: ($window.innerHeight - 112) + 'px'
};
$window.addEventListener('resize', onResize);
function onResize() {
self.listStyle.height = ($window.innerHeight - 112) + 'px';
if(!$scope.$root.$$phase) $scope.$digest();
} <md-virtual-repeat-container id="vertical-container" ng-style="ctrl.listStyle">
...
</md-virtual-repeat-container> |
@colinskow - that does work better, but it seems like the internal EDIT: it's not a CSS issue, the problem is that the virtual repeater runs before that sizing script and renders a smaller number of items. Maybe there's a way to solve it with a directive and priorities? EDIT: this is my solution, it calls an internal
|
@Madd0g if I open and close the Javascript console or developer tools, it will thereafter render an incorrect height. As long as I don't do that, my implementation seems to render correctly. Do you have a CodePen to demonstrate your issue? |
Here's my CSS that is working perfectly. Note that the repeat items all must be the EXACT specified height without any padding or overflow, otherwise scrolling will be really glitchy. #vertical-container {
min-height: 300px;
width: 100%;
}
.repeated-item {
border-bottom: 1px dotted #757575;
box-sizing: border-box;
height: 50px;
overflow: hidden;
margin-right: 16px;
} The |
@colinskow - it's definitely something about my HTML that's causing it (and weirdly it only breaks on ui-router state change, not a page refresh), but the directive I posted solves my problem perfectly, so I'm not worried, it will be enough for me until the virtual repeater is officially flexable. Thanks for your help |
+1 |
1 similar comment
+1 |
This issue is closed as part of our deprecation effort. |
+1 |
2 similar comments
+1 |
+1 |
+1 |
1 similar comment
+1 |
Please use the reaction feature instead of posting more "+1" updates to this thread. |
@jualvarez It is, but that was some time ago. I'll see if I can remake it using the latest updates and if so I'll submit a PR :) |
I'm a little out of touch following the MD issues, what do you mean by 'reaction feature'? |
Sorry for not being clearer. Read about reactions here: On 18 Sep 2016 23:17, "nkoterba" notifications@github.com wrote:
|
I found a little workaround that worked for me, first make a class like this:
and next in the HTLM do something like this:
PD: sorry for my english |
I added below css
|
Has anyone found a reliable way to set the height using a directive or otherwise? Ideally the height would be responsive, but without setting it explicitly in the CSS the virtual repeat container will not layout anything at all. I've tried setting it in the link function of a directive but simply attaching a directive to my md-virtual-repeat-container element will cause it to not lay out any items, even if the directive doesn't do anything. |
Ugh. The problem with my directive was that it had a controller attached to it and that was preventing it from working properly when I eventually did find the correct method. Here is a working directive that will resize the container:
Doesn't seem like |
+1 responsive |
None of those answers quite worked for me. I ended up coding a new solution. This one just updates with window resize. In my build, I've got a fixed footer.
Then add it here: |
for me this worked md-virtual-repeat-container {
height: calc(100vh - 75px);
} |
There is work happening in PR #11516 to allow variable height items in autocomplete via Also the Angular CDK has a |
codepen: http://codepen.io/uriva/pen/doxdVP
The text was updated successfully, but these errors were encountered: