6

I have angularJS ng-repeat i wanted to add scroll bar to the list items because it might have 4000 character in the field so in that case how can i set scroll bar based on rows or max-height for the div ?

main.html

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-primary">
            <div class="panel-heading clearfix">
                <h3 class="panel-title">Notification<span class="badge">{{tests.length}}</span></h3>
            </div>
            <div class="panel-body">
                <ul>
                    <li class="slide" ng-repeat="test in tests">
                        <div class="alert" role="alert" ng-class="{'alert-info': notification === 'H'}">
                            <span>{{test}}</span>
                        </div>
                    </li>   
                </ul>
            </div>
      </div>    
    </div>
</div>
3
  • max-height: xxx and overflow-y:auto for panel-body ? Commented May 16, 2016 at 15:00
  • what you think i should add helper class to achieve this task because we have panel body across application that will be impacted ? Commented May 16, 2016 at 15:06
  • Depends on what you want to achieve, but yeah, IMO it would be better to add extra class, than to overwrite the standard one. Commented May 16, 2016 at 15:09

3 Answers 3

13

I think this an HTML problem. Try to add this CSS to your code:

.panel-body {
    overflow: scroll;
    height: 100px;
}

overflow is a combination of overflow-x and overflow-y. If you only need to add scrollbars for vertical overflow, only take overflow-y: scroll; If you dont want to see the scrollbar when content small, try overflow: auto.

Sign up to request clarification or add additional context in comments.

Comments

3

I think OP wants to have the scroll when the retrieved data (tests) is a certain value. ng-class is your friend here.

<style>
    .conditionalScroll{
        width: 100%;
        height: 225px; /*change to your liking*/
        overflow: scroll;
    }
</style>
<!-- you may change threshold to your liking as well -->
<div ng-class="{conditionalScroll:tests.length>100}">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-primary">
                <div class="panel-heading clearfix">
                    <h3 class="panel-title">Notification<span class="badge">{{tests.length}}</span></h3>
                </div>
                <div class="panel-body">
                    <ul>
                        <li class="slide" ng-repeat="test in tests">
                            <div class="alert" role="alert" ng-class="{'alert-info': notification === 'H'}">
                                <span>{{test}}</span>
                            </div>
                        </li>   
                    </ul>
                </div>
          </div>    
        </div>
    </div>
</div>

Comments

2

I think you just need to add a style for the class 'panel-body' containining the max-height and overflow value... like the below:

CSS

.panel-body {max-height:400px;overflow:scroll;}

or if you want to add another class so you dont affect the panel-body class then either add a new class in the panel-body on that page like below

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-primary">
            <div class="panel-heading clearfix">
                <h3 class="panel-title">Notification<span class="badge">{{tests.length}}</span></h3>
            </div>
            <div class="panel-body panel-scroll">
                    <ul>
                        <li class="slide" ng-repeat="test in tests">
                            <div class="alert" role="alert" ng-class="{'alert-info': notification === 'H'}">
                                <span>{{test}}</span>
                            </div>
                        </li>   
                    </ul>
            </div>
      </div>    
    </div>
 </div>

CSS

.panel-scroll {max-height:400px;overflow:scroll;} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.