我正在使用jQuery数据表。

我想删除默认情况下添加到表中的搜索栏和页脚(显示有多少行可见)。我只是想用这个插件来排序。这能做到吗?


当前回答

我通过为footer分配一个id,然后使用css进行样式化来做到这一点:

    <table border="1" class="dataTable" id="dataTable_${dtoItem.key}" >
     <thead>
        <tr>
            <th></th>

        </tr>
    </thead>
 <tfoot>
    <tr>
            <th id="FooterHidden"></th>
    </tr>
</tfoot>
<tbody>

    <tr>

                <td class="copyableField"></td>

    </tr>
 </tbody>
</table>

然后使用CSS样式:

#FooterHidden{
   display: none;
}

如上所述的方法并不适合我。

其他回答

这可以通过简单地改变配置来完成:

$('table').dataTable({
      paging: false, 
      info: false
 });

但要隐藏空页脚;这段代码做到了:

 $('table').dataTable({
      paging: false, 
      info: false,

      //add these config to remove empty header
      "bJQueryUI": true,
      "sDom": 'lfrtip'

});
var table = $("#datatable").DataTable({
   "paging": false,
   "ordering": false,
   "searching": false
});

如果你正在使用自定义过滤器,你可能想隐藏搜索框,但仍然想启用过滤器功能,所以bFilter: false不是方法。使用dom: 'lrtp'代替,默认是'lfrtip'。文档:https://datatables.net/reference/option/dom

对于数据表>=1.10,使用:

$('table').dataTable({searching: false, paging: false, info: false});

如果你仍然想要这个插件的.search()函数,你需要用dom设置“隐藏”搜索栏html:

$('table').dataTable({dom: 'lrt'});

默认值是lfrtip或<"H"lfr>t<"F"ip>(当jQueryUI为true时),F char表示dom中的过滤(搜索)html, ip表示信息和分页(页脚)。

对于<1.10的数据表,使用:

$('table').dataTable({bFilter: false, bInfo: false});

或者使用纯CSS:

.dataTables_filter, .dataTables_info { display: none; }

如果你只是想隐藏搜索表单,例如,因为你有列输入过滤器,或者可能是因为你已经有一个CMS搜索表单能够从表中返回结果,那么你所要做的就是检查表单并获得它的id -(在写这篇文章的时候,它看起来像这样[tableid]-table_filter. datatables_filter)。然后简单地执行[tableid]-table_filter.dataTables_filter{display:none;}保留数据表的所有其他特性。