[英]How can I check if a given data table has been rendered
I have a function that selects all checkboxes ( selecionarTodos()
) on all pages of a table ( #tbTarefas
).我有一个 function 选择表( #tbTarefas
)所有页面上的所有复选框( selecionarTodos()
)。 However, I want to use the same method to select all checkboxes in other tables, which have the same structure, only with different id
.但是,我想对 select 其他表中的所有复选框使用相同的方法,这些复选框具有相同的结构,只是具有不同的id
。
I would like to check if a certain table is rendered at that moment on screen.我想检查某个表格当时是否在屏幕上呈现。 Something like that.类似的东西。
Before前
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;
}
}
After ( Initial thinking )之后(初步思考)
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;
}
}
}
Datatables has a callback for once initialization has been completed.一旦初始化完成,Datatables 就会有一个回调。
$('#tbTarefas').on( 'init.dt', function () {
}
Or on each redraw use "draw.dt"或者在每次重绘时使用“draw.dt”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.