简体   繁体   English

如何查看Dom中表格的所有行?

[英]How could i see all rows of my table in Dom?

I have applied data table on my table and it is working fine. 我已经在表上应用了数据表,并且工作正常。 Please check CodePen's link 请检查CodePen的链接

$(document).ready(function() {



  var table = $('#example').DataTable({ 
        select: false,
        "columnDefs": [{
            className: "Name", 
            "targets":[0],
            "visible": false,
            "searchable":false
        }]
    });//End of create main table


  $('#example tbody').on( 'click', 'tr', function () {

    alert(table.row( this ).data()[0]);

} );
}); 

but it is not loading all the rows(57) in Dom because of Pagination. 但是由于分页,它没有加载Dom中的所有行(57)。 i have a situation where i need the pagination and want all rows in dom too. 我遇到的情况是我需要分页并且也想要dom中的所有行。 Disabling the paging is not an option. 禁用分页不是一种选择。

Since your datatable use client side rendering, you can access to all your datas with this api -> data() 由于您的数据表使用客户端渲染,因此您可以使用此api-> data()访问所有数据

simple usage from your fiddle 小提琴的简单用法

var table = $('#example').DataTable({ 
    select: false,
    "columnDefs": [{
        className: "Name", 
        "targets":[0],
        "visible": false,
        "searchable":false
    }]
});//End of create main table

$('#example tbody').on( 'click', 'tr', function () {

   alert(table.row( this ).data()[0]);

});

table.data().each(function(d){console.log(d)}) // this will print all your data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM