JQuery 数据表就绪事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5399217/
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
JQuery Datatables ready event?
提问by Matthew
Is there an event that fires when a datatable has finished rendering? i.e. when I can begin modifying the HTML output. I am trying to add a row of <select>
's above my column headers, as is shown in the example on http://www.datatables.net/examples/api/multi_filter_select.html
当数据表完成渲染时是否会触发事件?即何时可以开始修改 HTML 输出。我正在尝试在<select>
列标题上方添加一行's,如http://www.datatables.net/examples/api/multi_filter_select.html上的示例所示
I've not been able to get this to work with my script. My data source is a javascript array as per http://www.datatables.net/examples/data_sources/js_array.htmland I've got a feeling that the multi filter select (see link above) doesn't work in conjunction with this.
我一直无法让它与我的脚本一起工作。我的数据源是一个 javascript 数组,按照http://www.datatables.net/examples/data_sources/js_array.html,我觉得多过滤器选择(见上面的链接)不能与这个。
Basically, I get nothing when iterating over the table headers using the following:
基本上,在使用以下内容迭代表头时,我一无所获:
$('table#id thead tr th').each(function() { ... })
I believe it's because the set of elements passed to each
is empty but I'm 100% sure the selector is correct and have verified this using FireQuery.
我相信这是因为传递给的元素集each
是空的,但我 100% 确定选择器是正确的,并且已经使用 FireQuery 验证了这一点。
I've found this http://www.datatables.net/examples/advanced_init/events_post_init.htmlwhich claims to have information on post-init events but it doesn't seem to be what I want.
我发现这个http://www.datatables.net/examples/advanced_init/events_post_init.html声称有关于 post-init 事件的信息,但它似乎不是我想要的。
Has anyone run into this before and found a solution? Thanks!
有没有人遇到过这个问题并找到了解决方案?谢谢!
回答by Virat
fnInitComplete
初始化完成
http://datatables.net/usage/callbacksI tried using this and it renders the select boxes in the footer.
http://datatables.net/usage/callbacks我尝试使用它并在页脚中呈现选择框。
But when I select something in the listbox and use fnFilter I get the error message
但是当我在列表框中选择某些内容并使用 fnFilter 时,我收到错误消息
Uncaught TypeError: Cannot call method 'replace' of undefined
未捕获的类型错误:无法调用未定义的方法“替换”
I tried fnFilter using a button click where I get a message Uncaught TypeError: Cannot read property 'nTr' of undefined
我尝试使用按钮单击 fnFilter,我收到一条消息 Uncaught TypeError: Cannot read property 'nTr' of undefined
回答by Marcus Hoelscher
I would use "fnDrawCallback" (see: https://www.datatables.net/usage/callbacks)
我会使用“fnDrawCallback”(见:https://www.datatables.net/usage/callbacks )
$(document).ready( function() {
$('#example').dataTable( {
"fnDrawCallback": function( oSettings ) {
// Your function(s);
}
} );
} );
I use this callback to bind events to elements that have been created by the datatable.
我使用此回调将事件绑定到由数据表创建的元素。