javascript - HTML javascript 动态调整表格大小

标签 javascript jquery html datatables html-table

我正在尝试复制这个示例
http://www.datatables.net/release-datatables/examples/api/multi_filter.html

当表很大时,它会将大小调整为 10 个条目并相应地对它们进行分页。我不需要任何其他东西。不需要搜索栏

目前,我从网站上获取了 JS 脚本,但在实现此脚本时遇到了困难。有人可以帮我吗?我有一张像这样的 table <table id="example" class="display" cellspacing="0" width="100%">带有 thead 和 tfoot 以及此 JavaScript 代码

    <script type="text/javascript" class="init">

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

    // DataTable
    var table = $('#example').DataTable();

    // Apply the search
    table.columns().every( function () {
        var that = this;

        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );
} );

    </script>

现在它没有调整表格的大小。这可能是一个非常基本的实现,但我似乎无法让它工作。请帮忙。

最佳答案

在 HTML 中添加 CSS

tfoot input {
    width: 100%;
    padding: 3px;
    box-sizing: border-box;
}

它能解决您的问题吗?

结果:https://jsfiddle.net/cmedina/7kfmyw6x/20/

关于javascript - HTML javascript 动态调整表格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36087236/

相关文章:

html - :link around div - styling inside div

javascript - JQueryUI SwitchClass 对 Javascript 没有影响

javascript - 将数组从 MVC Controller 传递到 Javascript

javascript - 使用 JavaScript 检测 iOS 5 或更高版本

javascript - jQuery 找到最近的

javascript - 单击按钮没有响应

javascript - 加载时、调整大小时和滚动时 - 运行单独功能的最佳方式是什么?

jquery - 在 iPhone 上 - jquery 打开/关闭嵌套导航

java - 将 JxBrowser 内容添加到 JPanel

html - 高度自动使元素消失