Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 570185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:22:26+00:00 2026-05-13T13:22:26+00:00

Have JSP page with dynamically generated HTML table with unknown number of rows. Have

  • 0

Have JSP page with dynamically generated HTML table with unknown number of rows.

Have property on backend, that sets maximum number of rows, e.g: max_rows=15.

How to limit number of rows for HTML table to max_rows value?
Other part of table should be accessible by vertical scroll,it means that user see 15 rows and if to scroll down, that it will be seen other rows of table.

It can be done empirically by calculating average height of row and using max-height property for div-wrapper, but i think this approach is not very stable.

So it’s needed to rely on row count.
Perhaps there is plugin for such case or it’s standard CSS or HTML solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:22:27+00:00Added an answer on May 13, 2026 at 1:22 pm

    This can be done with standard HTML, CSS and a bit of javascript. It can be made to degrade gracefully for clients with javascript turned off too. By that I mean, they’ll just see the original table, unmodified by scrollbars. Try something like this:

    <html>
    <head>
        <style type="text/css">
            table {
                width:  100%;
                border-collapse: collapse;
            }
            td {
                border: 1px solid black;
            }
            .scrollingTable {
                width: 30em;
                overflow-y: auto;
            }
        </style>
        <script type="text/javascript">
            function makeTableScroll() {
                // Constant retrieved from server-side via JSP
                var maxRows = 4;
    
                var table = document.getElementById('myTable');
                var wrapper = table.parentNode;
                var rowsInTable = table.rows.length;
                var height = 0;
                if (rowsInTable > maxRows) {
                    for (var i = 0; i < maxRows; i++) {
                        height += table.rows[i].clientHeight;
                    }
                    wrapper.style.height = height + "px";
                }
            }
        </script>
    </head>
    <body onload="makeTableScroll();">
        <div class="scrollingTable">
            <table id="myTable">
                <tr>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                </tr>
                <tr>
                    <td>Here is some long text that should wrap: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                </tr>
                <tr>
                    <td>blah</td>
                    <td>blah</td>
                    <td>blah</td>
                    <td>blah</td>
                </tr>
                <tr>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                </tr>
                <tr>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                </tr>
                <tr>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                    <td>blah blah</td>
                </tr>
                <tr>
                    <td>blah</td>
                    <td>blah</td>
                    <td>blah</td>
                    <td>blah</td>
                </tr>
            </table>
        </div>
    </body>
    </html>
    

    This was tested in Firefox, Chrome and IE 7, but it should work all modern browsers. Note that it doesn’t matter how tall the content of each row is, or how much padding each cell has. If you don’t want to use border-collapse:collapse on your table, then you’ll have to add code in the for loop to take cellspacing into account.

    If you have thicker borders, then replace the javascript function with this one:

    function makeTableScroll() {
        // Constant retrieved from server-side via JSP
        var maxRows = 4;
    
        var table = document.getElementById('myTable');
        var wrapper = table.parentNode;
        var rowsInTable = table.rows.length;
        try {
            var border = getComputedStyle(table.rows[0].cells[0], '').getPropertyValue('border-top-width');
            border = border.replace('px', '') * 1;
        } catch (e) {
            var border = table.rows[0].cells[0].currentStyle.borderWidth;
            border = (border.replace('px', '') * 1) / 2;
        }
        var height = 0;
        if (rowsInTable > maxRows) {
            for (var i = 0; i < maxRows; i++) {
                height += table.rows[i].clientHeight + border;
            }
            wrapper.style.height = height + "px";
        }
    }
    

    The try/catch in there handles the differences between IE and other browsers. The code in the catch is for IE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some static html content (included on a dynamically generated page) that I
I have a jsp page in which rows are created dynamically to a table
The Scenario I have a table on a web page that is dynamically generated
I have a jsp page in which rows of a table are added dynamically.
I have a functional JSP page that accepts URL parameters and updates a table
I have a jsp page in which there is a html table. The contents
I have a .jsp page where I have a GUI table that displays records
I have JSP page that contains table. when I click on one row of
I'm using Spring Web Flow (v. 1.0.5) and I have a JSP page that
I have jsp page that contains <span class=requiredFieldsMessageAsterix>*</span> I use a jsp include to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.