views:

264

answers:

1

I'm using a YUI DataTable with a checkbox column like this:

var myColumnDefs = [
    {key:"check", label:'', formatter:"checkbox"},                               
    {other columns...}
];

How can I iterate over all the rows that have been checked?

UPDATE

Here is my current work-around:

YUI().use("node", function(Y) {
    var records = myDataTable.getRecordSet().getRecords();

    for (i=0; i < records.length; i++) {
        // navigate to each individual input check box with YUI3 DOM selection
        if Y.one('#' + records[i].getId() + ' td div.yui-dt-liner input.yui-dt-checkbox').get('checked'){
            // checkbox is checked
        } 
    }
}

This uses the YUI2 Datatable and the YUI3 selector interface.

A: 

A better approach might be to subscribe to the checkboxClickEvent of the Datatable, then when a check box is selected (or unselected) programmatically mark the row as selected using the selectRow/unselectRow method of the Datatable. If you do this, it looks better in the UI (the rows are highlighted) and it is easy to get the selected rows using the getSelectedRows method of the Datatable.

whitey
Good idea, this approach has problems with the user pressing Back. After pressing back some checkboxes may remained checked, but since the onclick events for each checkbox didn't fire this page load they are not marked as being checked.
Justin Tanner