Call click event on last clicked row in YUI datatable

隐身守侯 提交于 2019-12-07 09:50:16

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/3022436/call-click-event-on-last-clicked-row-in-yui-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!