向 jQuery 数据表添加刷新按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11414508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:35:17  来源:igfitidea点击:

Adding a refresh button to jQuery Datatable

jquerydatatables

提问by SKR

I have a dataTable in my application. I am required to add a Refresh button somewhere near Search textbox within the datatable in order to refresh the table when user clicks on it. I have figured out the refresh functionality.

我的应用程序中有一个数据表。我需要在数据表中搜索文本框附近的某处添加一个刷新按钮,以便在用户单击它时刷新表。我已经弄清楚了刷新功能。

The thing that I am stuck with is how do I include this button within the datatable? I want to access this button idin my end script.

我遇到的问题是如何在数据表中包含这个按钮?我想id在我的结束脚本中访问这个按钮。

Any suggestions? Also can anyone tell what is the use of bJQueryUI?

有什么建议?还有谁能告诉我有什么用bJQueryUI

回答by SKR

I simply used the following code:

我只是使用了以下代码:

$('<button id="refresh">Refresh</button>').appendTo('div.dataTables_filter');

回答by devlife

Here is the example page for adding buttons from datatables.net

这是从 datatables.net 添加按钮的示例页面

http://datatables.net/examples/advanced_init/dom_toolbar.html

http://datatables.net/examples/advanced_init/dom_toolbar.html

And here is the example page for sDom as mentioned by @Mike: http://datatables.net/release-datatables/examples/advanced_init/dom_multiple_elements.html

这是@Mike 提到的 sDom 示例页面:http://datatables.net/release-datatables/examples/advanced_init/dom_multiple_elements.html

回答by Drakkainen

You could just make a double header and use the second one for a button.

您可以制作一个双标题并将第二个标题用于按钮。

bJqueryUI allows you to use jQueryUI themes or the theme roller. So if you add the jQueryUI before you initialize datatable you could use that style instead of the default one.

bJqueryUI 允许您使用 jQueryUI 主题或主题滚轮。因此,如果您在初始化数据表之前添加 jQueryUI,您可以使用该样式而不是默认样式。

回答by Mike

I had a similar issue that I was able to solve using the sDom parameter of datatables.

我有一个类似的问题,我可以使用数据表的 sDom 参数来解决。

http://datatables.net/forums/discussion/37/the-sdom-parameter/p1

http://datatables.net/forums/discussion/37/the-sdom-parameter/p1

Basically it allows you to place a div with an id within the datatable. I then used javascript to insert the button into that div.

基本上它允许您在数据表中放置一个带有 id 的 div。然后我使用 javascript 将按钮插入到该 div 中。