带有页脚的 jQuery DataTable 不响应

标签 jquery html twitter-bootstrap css datatables

当我在表格中添加 tfoot 时,表格不响应

我已经按照这个例子 https://datatables.net/examples/api/multi_filter.html

当我的页脚仅包含文本时,则为响应式,但当页脚中输入输入时,则为响应式

HTML:

<div class="row">
<div class="col-sm-12">
    <h2>Persons</h2>
</div>
<div class="col-sm-12">
<table id="tblPersons" class="table display table-hover table-striped userTables" >
<thead>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Email</th>
        <th>Telephone</th>
    </tr>
</thead>
<tfoot>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Email</th>
        <th>Telephone</th>
    </tr>
</tfoot>
<tbody>

JS:

$('#tblPersons thead th').each( function () {
    var title = $('#tblPersons tfoot th').eq($(this).index()).text();
    $(this).html('<input type="text" class="form-control" placeholder="Search '+title+'" />');
});

var table=$("#tblPersons").DataTable({
    bSort:true,
    bPaginate:true,
    bFilter:true,
    bInfo:false,
    //"bLengthChange": false,
    responsive:true
});

table.columns().eq(0).each( function ( colIdx ) {
    $( 'input', table.column( colIdx ).header() ).on( 'keyup change', function () {
        table.column( colIdx ).search( this.value ).draw();
    });

    $('input', table.column(colIdx).header()).on('click', function(e) {
        e.stopPropagation();
    });
});

最佳答案

尝试使输入变得流动:

#tblPersons input {
    width: 100%;        
    box-sizing: border-box;
}

关于带有页脚的 jQuery DataTable 不响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37000599/

相关文章:

jquery - 使用 jquery 从 json 字符串中的键中删除引号

javascript - 在 javascript 中将数据从一个对象传递到另一个对象

javascript - 遍历 DOM 以选择特定的 child 进行 e2e 测试

javascript - 捕获 HTML 输入元素值的所有更改的现代方法是什么?

javascript - 带有自定义服务器端的 bootstrap formvalidation.io 远程验证器返回错误消息

jquery - 用内容做半圈

javascript - 使用 JavaScript 三元运算符的 CSS 规则

twitter-bootstrap - 'for' 在 Bootstrap 形式标签中用于什么?

javascript - jQuery 展开/折叠表格行在展开时不显示

javascript - 如何使用 Bootstrap 和 Angular 表单逐步验证表单?