views:

270

answers:

1

Hello,

I have a YUI datatable and I have a function which is invoked when I click on a row:

...
YAHOO.keycoes.myDatatable = myDatatable;
...
myDatatable.subscribe("rowClickEvent", oneventclickrow);
var oneventclickrow = function( args ) {
    ...
}

I'd like to invoke the function subscribed to rowClickEvent on the row which is currently highlighted in the datatable (the row which was clicked for the last time).

I've tried to do something like this:

YAHOO.keycoes.myDatatable.getSelectedRows()[0].rowClickEvent()

but getSelectedRows() doesn't return any row. How can I get the highlighted row in the datatable and then call the function associated with rowClickEvent?

Thanks

A: 

Here goes a powerful application when i show YUI datatable funcionality. See its source code To get a good insight how i use YUI datatable.

I use a helper like

var datatableUtils = {
    getSelected:function(datatable) {
        var records = datatable.getRecordSet().getRecords();

        for(var i = 0; i < records.length; i++) {
            if(datatable.isSelected(records[i])) {
                return records[i];
            }
        }

        return null;
    },
    removeAll:function(datatable) {
        var records = datatable.getRecordSet().getRecords();

        for(var i = (records.length - 1); i >= 0; i--) {
            datatable.deleteRow(records[i]);
        }
    },
    removeSelected:function(datatable) {
        datatable.deleteRow(datatableUtils.getSelected(datatable));
    },
    selectAll:function(datatable) {
        var records = datatable.getRecordSet().getRecords();

        for(var i = 0; i < records.length; i++) {
            datatable.selectRow(records[i]);
        }
    }
};

And when i want to subscribe some event, i do as follows

datatable.user.subscribe("rowClickEvent", function(args) {
  /**
    * Keep in mind this keyword refers To YUI datatable instance 
    *
    * args.target allows yui get row clicked
    */

     if(this.isSelected(args.target)) {
         alert("row selected");
     }
}

I hope It can be useful

Arthur Ronald F D Garcia