How to loop through selected rows?

How to loop through selected rows?

gh2mgh2m Posts: 63Questions: 16Answers: 0

I read somewhere selected:true only works for column/cell, not row. How do I get a handle on selected row for looping through all the selected rows?

Answers

  • kthorngrenkthorngren Posts: 20,294Questions: 26Answers: 4,768

    Use rows().every() with the row() selector-modifier of {selected:true}.

    Kevin

  • gh2mgh2m Posts: 63Questions: 16Answers: 0

    I used following. It returns all the column 8 value instead of selected row column 8 value. What did I do wrong?

    function appendSelectedControls(table) {
    var selcntrls = document.getElementById("selectedcontrolsforteststep");
    selcntrls.innerHTML = ""; //reset it

    let rows = table.rows('.selected');
    alert("# of selected="+rows.data().length);  //it shows number of selected row
    if(rows.data().length > 0 ) {
        table.rows().every(function(rowIdx, tableLoop, rowLoop){
            let docid = table.cell(this, 8).data();
    
            selcntrls.appendChild(document.createTextNode(docid+"; "));
        });
    }
    

    }

  • gh2mgh2m Posts: 63Questions: 16Answers: 0

    My bad. I didn't even look.

    Replaced table.rows() with rows on line 4. It works fine now.

    Thank you very much.

This discussion has been closed.