如何删除 jQuery DataTables 插件添加的搜索栏和页脚?

发布于 2024-08-15 07:59:09 字数 150 浏览 6 评论 0原文

我正在使用 jQuery DataTables

我想删除默认添加到表格中的搜索栏和页脚(显示可见的行数)。基本上我只想使用这个插件进行排序。这可以做到吗?

I am using jQuery DataTables.

I want to remove the search bar and footer (showing how many rows there are visible) that is added to the table by default. I just want to use this plugin for sorting, basically. Can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(23

强辩 2024-08-22 07:59:09

对于 DataTables >=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 表示信息和分页(页脚)。

对于 DataTables <1.10,使用:

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

或使用纯 CSS:

.dataTables_filter, .dataTables_info { display: none; }

For DataTables >=1.10, use:

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

If you still want to be able to use the .search() function of this plugin, you will need to hide the search bar's html with the dom setting:

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

The defaults are lfrtip or <"H"lfr>t<"F"ip> (when jQueryUI is true), f char represents the filter (search) html in the dom, ip for the info and pagination (footer).

For DataTables <1.10, use:

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

or using pure CSS:

.dataTables_filter, .dataTables_info { display: none; }
攀登最高峰 2024-08-22 07:59:09

查看 http://www.datatables.net/examples/basic_init/filter_only.html 获取列表显示/隐藏的功能。

你想要的是将“bFilter”和“bInfo”设置为 false;

$(document).ready(function() {
    $('#example').dataTable( {
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false
                 } );
} );

Check out http://www.datatables.net/examples/basic_init/filter_only.html for a list of features to show/hide.

What you want is to set "bFilter" and "bInfo" to false;

$(document).ready(function() {
    $('#example').dataTable( {
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false
                 } );
} );
巴黎盛开的樱花 2024-08-22 07:59:09

您也可以通过设置 sDom 来完全不绘制页眉或页脚:http:// /datatables.net/usage/options#sDom

'sDom': 't' 

将仅显示表格,不显示页眉或页脚或任何内容。

这里讨论了一些: http: //www.datatables.net/forums/discussion/2722/how-to-hide-empty-header-and-footer/p1

You can also not draw the header or footer at all by setting sDom: http://datatables.net/usage/options#sDom

'sDom': 't' 

will display JUST the table, no headers or footers or anything.

It's discussed some here: http://www.datatables.net/forums/discussion/2722/how-to-hide-empty-header-and-footer/p1

柠檬心 2024-08-22 07:59:09

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

If you are using custom filter, you might want to hide search box but still want to enable the filter function, so bFilter: false is not the way. Use dom: 'lrtp' instead, default is 'lfrtip'. Documentation: https://datatables.net/reference/option/dom

伪心 2024-08-22 07:59:09
var table = $("#datatable").DataTable({
   "paging": false,
   "ordering": false,
   "searching": false
});
var table = $("#datatable").DataTable({
   "paging": false,
   "ordering": false,
   "searching": false
});
深居我梦 2024-08-22 07:59:09

一种快速但肮脏的方法是找出页脚的类并使用 jQuery 或 CSS 隐藏它:

$(".dataTables_info").hide();

A quick and dirty way is to find out the class of the footer and hide it using jQuery or CSS:

$(".dataTables_info").hide();
宫墨修音 2024-08-22 07:59:09

正如 @Scott Stafford 所说,sDOM 是显示、隐藏或重新定位组成 DataTable 的元素的最合适的属性。我认为 sDOM 现在已经过时了,通过实际补丁,该属性现在是 dom

这个属性也允许为元素设置一些类或id,这样你就可以更轻松地设计。

请在此处查看官方文档: https://datatables.net/reference/option/dom

这个示例只会显示表格:

$('#myTable').DataTable({
    "dom": 't'
});

As said by @Scott Stafford sDOM is the most apropiated property to show, hide or relocate the elements that compose the DataTables. I think the sDOM is now outdated, with the actual patch this property is now dom.

This property allows to set some class or id to an element too, so you can stylish easier.

Check the oficial documentation here: https://datatables.net/reference/option/dom

This example would show only the table:

$('#myTable').DataTable({
    "dom": 't'
});
固执像三岁 2024-08-22 07:59:09

如果您使用主题滚轮:

.dataTables_wrapper .fg-toolbar { display: none; }

if you are using themeroller:

.dataTables_wrapper .fg-toolbar { display: none; }
口干舌燥 2024-08-22 07:59:09
<script>
$(document).ready(function() {
    $('#nametable').DataTable({
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false
    });
});
</script>

在数据表构造函数中

https://datatables .net/forums/discussion/20006/how-to-remove-cross-icon-in-search-box

<script>
$(document).ready(function() {
    $('#nametable').DataTable({
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false
    });
});
</script>

in your datatable constructor

https://datatables.net/forums/discussion/20006/how-to-remove-cross-icon-in-search-box

亚希 2024-08-22 07:59:09

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

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

但是要隐藏空页脚;这段代码可以解决这个问题:

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

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

});

This can be done by simply changing the configuration:

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

But to hide the empty footer; this piece of code does the trick:

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

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

});
嘴硬脾气大 2024-08-22 07:59:09

在这里您可以将 sDom 元素添加到您的代码中,顶部搜索栏被隐藏。

$(document).ready(function() {
    $('#example').dataTable( {
"sDom": '<"top">rt<"bottom"flp><"clear">'
 } );
} );

Here you can add to sDom element to your code, top search bar is hidden.

$(document).ready(function() {
    $('#example').dataTable( {
"sDom": '<"top">rt<"bottom"flp><"clear">'
 } );
} );
最近可好 2024-08-22 07:59:09

提醒您不能在同一个 元素上初始化 DataTable 两次。

如果您遇到同样的问题,则可以设置 <在 HTML 上初始化 DataTable 时,code>searching 和 paging false,如下所示

 $('#tbl').DataTable({
    searching: false, 
    paging: false,
    dom: 'Bfrtip',
    buttons: [
       'copy', 'csv', 'excel', 'pdf', 'print'
    ]
 });

Just a reminder you can't initialise DataTable on the same <table> element twice.

If you encounter same issue then you can set searching and paging false while initializing DataTable on your HTML <table> like this

 $('#tbl').DataTable({
    searching: false, 
    paging: false,
    dom: 'Bfrtip',
    buttons: [
       'copy', 'csv', 'excel', 'pdf', 'print'
    ]
 });
只是我以为 2024-08-22 07:59:09

您可以使用 sDom 属性。代码看起来像这样。

$(document).ready(function() {
    $('#example').dataTable( {
        'sDom': '"top"i'
                 } );
} );

它隐藏搜索和寻呼机框。

You can use sDom attribute. Code looks something like this.

$(document).ready(function() {
    $('#example').dataTable( {
        'sDom': '"top"i'
                 } );
} );

İt hides search and pager box.

我一向站在原地 2024-08-22 07:59:09

从 DataTables 1.10.5 开始,现在可以定义初始化
使用 HTML5 data-* 属性的选项。

-dataTables 文档:HTML5 data-* 属性 - 表选项

因此,您可以在上指定data-searching="false" data-paging="false" data-info="false"。例如,此表不允许搜索、应用分页或显示信息块:

<table id="example" class="display" width="100%" data-searching="false" data-paging="false" data-info="false">
    <thead>
        <tr>
            <th>Name</th>
            <th data-orderable="false">Avatar</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td><img src="https://www.gravatar.com/avatar/8edcff60cdcca2ad650758fa524d4990?s=64&d=identicon&r=PG" alt="" style="width: 64px; height: 64px; visibility: visible;"></td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td><img src="https://www.gravatar.com/avatar/98fe9834dcca2ad650758fa524d4990?s=64&d=identicon&r=PG" alt="" style="width: 64px; height: 64px; visibility: visible;"></td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        ...[ETC]...
    </tbody>
</table>

请参阅 https 上的工作示例://jsfiddle.net/jhfrench/17v94f2s/

这种方法的优点是它允许您进行标准的 dataTables 调用(即 $('table.apply_dataTables').DataTable()),同时能够按表配置 dataTables 选项-桌子。

As of DataTables 1.10.5 it is now possible to define initialisation
options using HTML5 data-* attributes.

-dataTables documentation: HTML5 data-* attributes - table options

So you can specify data-searching="false" data-paging="false" data-info="false" on the table. For example, this table will not allow searching, apply paging, or show the information block:

<table id="example" class="display" width="100%" data-searching="false" data-paging="false" data-info="false">
    <thead>
        <tr>
            <th>Name</th>
            <th data-orderable="false">Avatar</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td><img src="https://www.gravatar.com/avatar/8edcff60cdcca2ad650758fa524d4990?s=64&d=identicon&r=PG" alt="" style="width: 64px; height: 64px; visibility: visible;"></td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td><img src="https://www.gravatar.com/avatar/98fe9834dcca2ad650758fa524d4990?s=64&d=identicon&r=PG" alt="" style="width: 64px; height: 64px; visibility: visible;"></td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        ...[ETC]...
    </tbody>
</table>

See a working example at https://jsfiddle.net/jhfrench/17v94f2s/.

The advantage to this approach is that it allows you to have a standard dataTables call (ie, $('table.apply_dataTables').DataTable()) while being able to configure the dataTables options table-by-table.

乖不如嘢 2024-08-22 07:59:09

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

If you only want to hide the search form for example because you have column input filters or may be because you already have a CMS search form able to return results from the table then all you have to do is inspect the form and get its id - (at the time of writing this, it looks as such[tableid]-table_filter.dataTables_filter). Then simply do [tableid]-table_filter.dataTables_filter{display:none;} retaining all other features of datatables.

单挑你×的.吻 2024-08-22 07:59:09

这对我有用 #table 是表的 ID

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

this worked for me #table is a Id of table

$('#table').dataTable({searching: false, paging: false, info: false});
长不大的小祸害 2024-08-22 07:59:09

它对我有用;

您可以使用表上的此属性删除搜索栏:data-searching="false"

It works for me;

You can remove search bar using this attribute on table : data-searching="false"

若言繁花未落 2024-08-22 07:59:09
$('#my_table').DataTable({
   "iDisplayLength": 100,
   "searching": false, 
   "paging": false,
   "info": false,
});
$('#my_table').DataTable({
   "iDisplayLength": 100,
   "searching": false, 
   "paging": false,
   "info": false,
});
眉黛浅 2024-08-22 07:59:09

你可以通过 css 隐藏它们:

#example_info, #example_filter{display: none}

You could hide them via css:

#example_info, #example_filter{display: none}
云淡风轻 2024-08-22 07:59:09

我认为最简单的方法是:

<th data-searchable="false">Column</th>

只编辑你要修改的表格,而不改变常见的CSS或JS。

I think the simplest way is:

<th data-searchable="false">Column</th>

You can edit only the table you have to modify, without change common CSS or JS.

素手挽清风 2024-08-22 07:59:09

无过滤输入控制。 (https://datatables.net/reference/option/dom)

    /* Results in:
        {length}
        {processing}
        {table}
        {information}
        {pagination}
    */
    $('#example').dataTable( {
      "dom": 'lrtip'
    } );

No filtering input control. (https://datatables.net/reference/option/dom)

    /* Results in:
        {length}
        {processing}
        {table}
        {information}
        {pagination}
    */
    $('#example').dataTable( {
      "dom": 'lrtip'
    } );
青衫负雪 2024-08-22 07:59:09
        $(document).ready(function() {          
        var table = $('#example').DataTable({
          dom: 'lrt',
          paging: false,
          info: false,
          "search": {
            "caseInsensitive": true
          }
        });
      $('#txtSearch').on('keyup change', function() {
        dataTable_Search($(this).val());
      });

      $('#btnClear').on('click', function() {
        $('#txtSearch').val('');
        dataTable_Search('');
      });

      function dataTable_Search(v) {
        table.search(v).draw();
      }
    });

提琴手:https://jsfiddle.net/godlymathew/mbn78xdh/

        $(document).ready(function() {          
        var table = $('#example').DataTable({
          dom: 'lrt',
          paging: false,
          info: false,
          "search": {
            "caseInsensitive": true
          }
        });
      $('#txtSearch').on('keyup change', function() {
        dataTable_Search($(this).val());
      });

      $('#btnClear').on('click', function() {
        $('#txtSearch').val('');
        dataTable_Search('');
      });

      function dataTable_Search(v) {
        table.search(v).draw();
      }
    });

Fiddler : https://jsfiddle.net/godlymathew/mbn78xdh/

九歌凝 2024-08-22 07:59:09

我通过为页脚分配一个 id 然后使用 css 进行样式设置来完成此操作:

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

然后使用 css 进行样式设置:

#FooterHidden{
   display: none;
}

如上所述,方法对我不起作用。

I have done this by assigning footer an id and then styling using css :

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

Then styling using css :

#FooterHidden{
   display: none;
}

As above mentioned ways aren't working for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文