微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何检查给定的数据表是否已呈现

如何解决如何检查给定的数据表是否已呈现

我有一个函数可以选择表 (selecionarTodos()) 的所有页面上的所有复选框 (#tbTarefas)。但是,我想使用相同的方法选择其他表中的所有复选框,这些表具有相同的结构,只是id不同。

我想检查某个表是否在屏幕上呈现。类似的东西。

之前

function selecionarTodos(source) {
        const tabela = $("#tbTarefas").DataTable();
        let celulasCheckBox = tabela.column(0).nodes();

        for (let i = 0; i < celulasCheckBox.length; i++) {
            let checkBox = celulasCheckBox[i].querySelector('input[type="checkBox"]');

            checkBox.checked = source.checked;
        }
    }

之后初步思考

function selecionarTodos(source) {
        const tabelaTarefas = $("#tbTarefas").DataTable();
        const tabelaAtendimento = $("#tbPendentes").DataTable();

        if (tabelaTarefas) {
            let CheckBoxTarefasTd = tabelaTarefas.column(0).nodes();

            for (let i = 0; i < CheckBoxTarefasTd.length; i++) {
                let checkBox = CheckBoxTarefasTd[i].querySelector('input[type="checkBox"]');

                checkBox.checked = source.checked;
            }
        }
        else if (tabelaAtendimento) {
            let CheckBoxAtendimentoTd = tabelaAtendimento.column(0).nodes();

            for (let i = 0; i < CheckBoxAtendimentoTd.length; i++) {
                let checkBox = CheckBoxAtendimentoTd[i].querySelector('input[type="checkBox"]');

                checkBox.checked = source.checked;
            }
        }
    }

enter image description here

解决方法

Datatables 在初始化完成后有一个回调。

$('#tbTarefas').on( 'init.dt',function () { 

}

或者在每次重绘时使用“draw.dt”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。