简体   繁体   中英

Call click event on last clicked row in YUI datatable

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM