Set maximum displayed rows count for HTML table

后端 未结 6 1667
情歌与酒
情歌与酒 2021-02-13 22:37

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

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 23:23

    Edit: This doesn't actually solve the problem proposed. I missed the part in the question that the user needs to be able to scroll to see the rest of rows. Whoops. So, I suppose js is actually needed.


    This can actually be done without javascript. The trick is using nth-child(x):

    table {
        border-collapse: collapse;
    }
    
    tr:nth-child(n + 4) {
        visibility: hidden;
    }
    

    The border-collapse is needed so the border doesn't extend beyond the hidden rows.

    Here's the fiddle.

提交回复
热议问题