3

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:

function getCheckedIds() {
    var records = yuiDataTable.getRecordSet().getRecords();
    var ids = '';

    for (i=0; i < records.length; i++) {
        var checked = false;
        if (records[i] != undefined)
        {
            checked = $('#' + records[i].getId() + ' td div.yui-dt-liner input.yui-dt-checkbox').attr('checked');
            if (checked) {
                if (ids != '') {
                    ids += ',';
                }
                ids += records[i].getData("item.id");
            }
        }
    }
    return ids;    
}
Justin Tanner
  • 14,062
  • 17
  • 82
  • 103
  • 1
    Justin -- There's a dedicated forum for YUI DataTable support -- http://yuilibrary.com/forum/viewforum.php?f=90 -- if you don't get an answer here on SO, you may want to try there. -Eric – Eric Miraglia Jun 14 '10 at 17:39

1 Answers1

2

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
  • 536
  • 5
  • 6
  • 1
    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 Jul 12 '10 at 08:36