如何遍历 DataTables jQuery 中的所有行? [英] How to loop through all rows in DataTables jQuery?

查看:60
本文介绍了如何遍历 DataTables jQuery 中的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jquery 插件 DataTables 来构建漂亮的表

I am using jquery plugin DataTables for building nice table

  var table = $('#example').DataTable({
    "data": source
});

我希望为表中的所有行制作一个

I would like that make an each for all rows in table

不幸的是,这种方式可能已经过时并且不适用于新版本(它会引发错误)

Unfortunately this way may be out of date and does't work with new version (it launchs an error)

$(table.fnGetNodes()).each(function () {

});

这种方式只适用于可见行(前 10 行,因为其他行是分页的)

And this way only works only for visibles rows (10 first rows because other rows are paginated)

 table.each( function ( value, index ) {
    console.log( 'Data in index: '+index+' is: '+value );
} );

请问您知道如何循环到所有行吗?

Do you known how to loop to all rows please?

推荐答案

我终于找到了:

 var data = table.rows().data();
 data.each(function (value, index) {
     console.log(`For index ${index}, data value is ${value}`);
 });

这篇关于如何遍历 DataTables jQuery 中的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆