Datatables-Instanz nicht mit DOM synchronisiert (Status des Eingabe-Kontrollkästchens)Python

Python-Programme
Guest
 Datatables-Instanz nicht mit DOM synchronisiert (Status des Eingabe-Kontrollkästchens)

Post by Guest »

Ich habe eine Tabelle my_tbl, die mit der jQuery-Bibliothek datatables2.1.8.js initialisiert wurde:

Code: Select all

/* using python django template because table template is not in the same html file */
{% include 'my_tbl_template.html' %}

let my_tbl=$('#my_tbl').DataTable({...}),
jede Zelle enthält ob anfänglich aktiviert oder nicht aktiviert;
Das Problem besteht genau darin, dass my_tbl dies nicht ist Synchronisiert mit dem HTML-Dom, nachdem der Status der Kontrollkästchen manuell geändert wurde! (aktivieren oder deaktivieren);
z. B. wenn ich zwei Kontrollkästchen (2 Zellen) anfangs beide aktiviert habe, wenn der Benutzer eines davon deaktiviert

Code: Select all

printCheckboxStatusDom()
gibt 1 //(erwartete Anzahl aktivierter Kontrollkästchen)
aber< aus br />

Code: Select all

printCheckboxStatusTbl()
gibt 2 //die anfänglich aktivierten Kontrollkästchen aus

Code: Select all

$(document).ready(function(){
$('input[type=checkbox]').change(function() {
printCheckboxStatusDom();  // prints correctly how many checkbox is checked at this time
printCheckboxStatusTbl(); //always prints initialized values (no change)
});

function printCheckboxStatusDom(){
let checkeds = $(document).find('input[type=checkbox]:checked');
console.log('DOM: checked boxes: ' + checkeds.length);
}

/* Function to print checkboxes status in the my_tbl instance */
function printCheckboxStatusTbl() {
my_tbl.rows().every(function (rowIdx, tableLoop, rowLoop) {
let rowNode = this.node();
let cellCheckboxes = $(rowNode).find('input[type=checkbox]:checked');
console.log('Tbl: checked boxes: ' + cellCheckboxes.length);

}
);
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post