如何删除 jQuery DataTables 插件添加的搜索栏和页脚?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(23)
对于 DataTables >=1.10,请使用:
如果您仍然希望能够使用此插件的
.search()
功能,则需要隐藏搜索栏带有dom
设置的 html:默认值为
lfrtip
或<"H"lfr>t<"F"ip>
(当>jQueryUI
为 true),f
char 表示 dom 中的过滤器(搜索)html,ip
表示信息和分页(页脚)。对于 DataTables <1.10,使用:
或使用纯 CSS:
For DataTables >=1.10, use:
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 thedom
setting:The defaults are
lfrtip
or<"H"lfr>t<"F"ip>
(whenjQueryUI
is true),f
char represents the filter (search) html in the dom,ip
for the info and pagination (footer).For DataTables <1.10, use:
or using pure CSS:
查看 http://www.datatables.net/examples/basic_init/filter_only.html 获取列表显示/隐藏的功能。
你想要的是将“bFilter”和“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;
您也可以通过设置 sDom 来完全不绘制页眉或页脚:http:// /datatables.net/usage/options#sDom
将仅显示表格,不显示页眉或页脚或任何内容。
这里讨论了一些: 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#sDomwill 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
如果您使用自定义过滤器,您可能想隐藏搜索框但仍想启用过滤器功能,因此
bFilter: false
不是方法。使用dom: 'lrtp'
代替,默认为'lfrtip'
。文档:https://datatables.net/reference/option/domIf 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. Usedom: 'lrtp'
instead, default is'lfrtip'
. Documentation: https://datatables.net/reference/option/dom一种快速但肮脏的方法是找出页脚的类并使用 jQuery 或 CSS 隐藏它:
A quick and dirty way is to find out the class of the footer and hide it using jQuery or CSS:
正如 @Scott Stafford 所说,
sDOM
是显示、隐藏或重新定位组成 DataTable 的元素的最合适的属性。我认为sDOM
现在已经过时了,通过实际补丁,该属性现在是dom
。这个属性也允许为元素设置一些类或id,这样你就可以更轻松地设计。
请在此处查看官方文档: https://datatables.net/reference/option/dom
这个示例只会显示表格:
As said by @Scott Stafford
sDOM
is the most apropiated property to show, hide or relocate the elements that compose the DataTables. I think thesDOM
is now outdated, with the actual patch this property is nowdom
.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:
如果您使用主题滚轮:
if you are using themeroller:
在数据表构造函数中
https://datatables .net/forums/discussion/20006/how-to-remove-cross-icon-in-search-box
in your datatable constructor
https://datatables.net/forums/discussion/20006/how-to-remove-cross-icon-in-search-box
这可以通过简单地更改配置来完成:
但是要隐藏空页脚;这段代码可以解决这个问题:
This can be done by simply changing the configuration:
But to hide the empty footer; this piece of code does the trick:
在这里您可以将
sDom
元素添加到您的代码中,顶部搜索栏被隐藏。Here you can add to
sDom
element to your code, top search bar is hidden.提醒您不能在同一个
元素上初始化
DataTable
两次。如果您遇到同样的问题,则可以设置 <在 HTML
上初始化 DataTable 时,code>searching 和
paging
false,如下所示Just a reminder you can't initialise
DataTable
on the same<table>
element twice.If you encounter same issue then you can set
searching
andpaging
false while initializing DataTable on your HTML<table>
like this您可以使用 sDom 属性。代码看起来像这样。
它隐藏搜索和寻呼机框。
You can use sDom attribute. Code looks something like this.
İt hides search and pager box.
-dataTables 文档:HTML5 data-* 属性 - 表选项
因此,您可以在
表
上指定data-searching="false" data-paging="false" data-info="false"
。例如,此表不允许搜索、应用分页或显示信息块:请参阅 https 上的工作示例://jsfiddle.net/jhfrench/17v94f2s/。
这种方法的优点是它允许您进行标准的 dataTables 调用(即
$('table.apply_dataTables').DataTable()
),同时能够按表配置 dataTables 选项-桌子。-dataTables documentation: HTML5 data-* attributes - table options
So you can specify
data-searching="false" data-paging="false" data-info="false"
on thetable
. For example, this table will not allow searching, apply paging, or show the information block: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.如果您只想隐藏搜索表单,例如因为您有列输入过滤器,或者可能是因为您已经有一个能够从表中返回结果的 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.这对我有用 #table 是表的 ID
this worked for me #table is a Id of table
它对我有用;
您可以使用表上的此属性删除搜索栏:data-searching="false"
It works for me;
You can remove search bar using this attribute on table : data-searching="false"
你可以通过 css 隐藏它们:
You could hide them via css:
我认为最简单的方法是:
只编辑你要修改的表格,而不改变常见的CSS或JS。
I think the simplest way is:
You can edit only the table you have to modify, without change common CSS or JS.
无过滤输入控制。 (https://datatables.net/reference/option/dom)
No filtering input control. (https://datatables.net/reference/option/dom)
提琴手:https://jsfiddle.net/godlymathew/mbn78xdh/
Fiddler : https://jsfiddle.net/godlymathew/mbn78xdh/
我通过为页脚分配一个 id 然后使用 css 进行样式设置来完成此操作:
然后使用 css 进行样式设置:
如上所述,方法对我不起作用。
I have done this by assigning footer an id and then styling using css :
Then styling using css :
As above mentioned ways aren't working for me.