繁体   English   中英

jQuery 使用带有分页的 table.rows().data().each 获取所有行

[英]jQuery get all rows using table.rows().data().each with pagination

我无法在网上找到解决方案。 我有这样的代码

$('.validation-summary-table').dataTable({ paging: true, ordering: false });
const conflictsArray = pushConflictDatas('#conflict .validation-summary-table tbody tr.odd');

function pushConflictDatas(dataTableTr) {
    let radioButtonsConflicts = new Array();
    $(dataTableTr).each(function() {
        const currentRow = $(this).closest("tr"); // CSV row
        const nextRow = currentRow.next(); // DB row

        let currentRowObj = {
            Name: currentRow.find('td:eq(0)').text().trim(),
            isChecked: currentRow.find('td:eq(1) input[type="radio"]').is(':checked')
        }

        let nextRowObj = {
            Name: nextRow.find('td:eq(0)').text().trim(),
            isChecked: nextRow.find('td:eq(1) input[type="radio"]').is(':checked')
        }

        radioButtonsConflicts.push([currentRowObj, nextRowObj]);
    });

    return radioButtonsConflicts;
}

这工作正常,直到我发现当我单击一个按钮时它并没有获得下一页上的所有表格行,只有当前页面而没有其他内容。 我需要获取所有行并将它们推送到一个数组,以满足我的 ajax 请求。 所以我从他们的文档中找到了这段代码:

var table = $(conflictTable).DataTable();

table.rows('.odd').data().each(function (value, index) {
    console.log('index: ', index)
    console.log('value: ', value)
} );

然而,这只会选择当前页面上的<tr> ,就像旧的 function 所做的那样。 如果我移至下一页,它将“追加”它。 如果我删除选择器.odd ,它会从所有分页页面中获取所有行,但我正在编写一个针对下一行的代码,我只想在执行此操作之前使用特定名称 class 的 select 行。 我该怎么做呢?

您可以使用以下代码获取所有表数据:

let table_data = table.rows({ search: 'applied'}).data();

暂无
暂无

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

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