检索元素的dataTable对象 [英] Retrieve dataTable object of element
问题描述
我正在尝试使用JQuery获取一个jQuery数据表的对象。我正在使用这个线程来实现这一点:
根据上面发布的链接,不应该这样做,而只是取得对象。
这是我的代码:
main.js
(加载到每个页面的HTML头)
$(document).ready(function(){
$(。dynamic-wide-table)。dataTable({
aaSorting:[],
scrollX :true,
scrollY:530,
scrollCollapse:true,
lengthMenu:[
[100,400,1000,5000,-1]
[100,400,1000,5000,全部]
],
检索:true
});
});
获取对象:
$(document).ready(function(){
$('。dynamic-wide-table')。dataTable();
});
遵循评论:
您将无法获取单个表对象,因为该类的每个元素都将拥有自己的 dataTable
对象。
您可以循环遍历类并检索每个类。为了获得单个元素 dataTable
对象,您将需要知道哪个表元素是您需要的对象:
$ b $ ($($)$($)$($)$($)$($($)$ b console.log('table no。'+ i);
//应将每个元素的dataTable对象打印到控制台
console.log($(this).dataTable());
});
});
理想的做法是给每个表格一个id,然后检索 dataTable
对象与id:
$('#tableId')。dataTable );
I am trying to get an object of a jQuery Data Table using JQuery. I am using this thread to accomplish this:
For some reason this does not work. When I call $('.dynamic-wide-table').dataTable();
it causes my table to initialize AGAIN and make the table render twice, like so:
According to the link posted above it should NOT be doing that, but instead just fetch the object.
Here is my code:
main.js
(loaded into HTML head of every page)
$(document).ready(function() {
$(".dynamic-wide-table").dataTable({
"aaSorting": [],
"scrollX": true,
"scrollY": 530,
"scrollCollapse": true,
"lengthMenu": [
[100, 400, 1000, 5000, -1],
[100, 400, 1000, 5000, "All"]
],
"retrieve": true
});
});
get object:
$(document).ready(function() {
$('.dynamic-wide-table').dataTable();
});
Following the comments:
You wont be able to get the single tables object because each element with that class will have it's own dataTable
object.
You could loop through the classes and retrieve each individual one. In order to get a single elements dataTable
object you will need to know which table element it is that you need the object from:
$(document).ready(function() {
$('.dynamic-wide-table').each(function(i){
console.log('table no. ' + i );
// Should print the dataTable object for each element to the console
console.log($(this).dataTable());
});
});
The ideal thing to do would be to give each individual table an id, then retrieve the dataTable
object with the id:
$('#tableId').dataTable();
这篇关于检索元素的dataTable对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!