javascript - 调整屏幕大小时,表格会达到最大高度

标签 javascript html css ajax css-tables

我有一个最小高度为 300 像素和最大高度为 650 像素的表格,这是完美的。唯一的问题是,当我调整窗口大小时,表格将一直向下延伸,直到显示其所有值。它应该有一个滚动条,这样您就可以在列表中移动,但一旦调整屏幕大小,滚动条就消失了,它只在一页上显示表格中的所有值。

CSS:

#tblPropertyGrid
{
    width: 250px; 
    min-height: 300px; 
    max-height: 650px; 
    font-size: 10px;
    overflow: scroll;
    margin-left:15px; 
}

HTML:

<div class='row'>
    <div class='thirdDiv' id="tabProperties">
        <script type="text/javascript">
                $(document).ready(function() {
                    $('#tblPropertyGrid').handsontable({
                        colHeaders: ["Name", "Value"],
                        colWidths: [115, 115],
                        maxCols: 2,
                        startCols: 2,
                        multiSelect: false,
                        afterSelectionEnd: function(row1, col1, row2, col2) {
                            $('.handsontableInputHolder').css('left', '114px');
                            $('.handsontableInputHolder').css('top', $('.htCore:first').children('tBody:first').children('tr')[row1].offsetTop + 'px');
                        },
                        afterChange: function(changes, source) {
                            if (changes != null && source == 'edit' && gridFilled)
                            {
                                var row = changes[0][0];
                                var col = changes[0][1];
                                var table = $('#tblPropertyGrid').handsontable('getInstance');
                                var currentItem = $(table.getCell(row, col));
                                var originalHTML = currentItem.html();
                                currentItem.html("EDITING...");

                                $.ajax({
                                    url: '@Url.Action("EditProperty", "Home")',
                                    type: "POST",
                                    data: { ID: Object.keys(selectedSections)[$(selectedSections).size() - 1], PropertyName: table.getCell(row, 0).innerHTML, NewValue: changes[0][3] } ,
                                    async: true
                                }).done(function(result) {
                                    if (result == "True")
                                    {
                                        currentItem.html(originalHTML);
                                        currentItem.css('background', 'lightgreen');
                                        currentItem.animate({backgroundColor:"white"}, 1500);
                                    }
                                    else
                                    {
                                        currentItem.html(originalHTML);
                                        currentItem.css('background', '#FF5959');
                                        //currentItem.animate({backgroundColor:"white"}, 1500);
                                    }
                                });
                            }
                        }
                    });

                    var table = $('#tblPropertyGrid').handsontable('getInstance');

                    while (table.countRows() > 1)
                    {
                        table.alter('remove_row', 1);
                    }

                    table.getCellMeta(0, 0).readOnly = true;
                    table.getCellMeta(0, 1).readOnly = true;

                    //Should show btnAdd?
                    if (GetURLParameter('id') != null)
                        $('#btnAdd').prop('disabled', false);
                    else
                        $('#btnAdd').prop('disabled', true);
                });
        </script>
        <h2 style="font-size: 14px;margin-top:20px" href="#tabProperties">Properties</h2>
        <div id="tblPropertyGrid"></div>
    </div>

最佳答案

表格具有“拉伸(stretch)以适合”的内置属性。

尝试将表格放在具有相同最大/最小高度和溢出属性的 div 中。

关于javascript - 调整屏幕大小时,表格会达到最大高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30846437/

相关文章:

html - Css 分页符在 IE 中的表格后导致额外的分页符

HTML5/CSS3 Circle inside a circle with inner circle stick on top inside the outer circle

带有内联 block 的 CSS 站点布局

jquery - 在滚动上使用 css 和 jQuery 创建模糊效果

jquery - 在jquery中逐一显示LI项目

CSS:Bootstrap 下拉菜单隐藏在网格单元后面

javascript - 如何确保工作不会在 Bull 中运行两次?

javascript - Backbone 路由器参数不工作

java - 在没有 Firefox 的情况下编辑 Firefox 首选项

JavaScript - Onclick 导航箭头功能问题