0

我尝试使用 jquery 数据表处理表的行上的双击事件如您所见,我尝试了一些事情,在 fnDrawCallback 内部,在使用 on() 或直接 dblckick() 准备好的文档内部,但它永远不会起作用;-( 它仅在以下情况下起作用我在表格元素上设置了它,但是这样,我没有得到行元素;-(

这是代码:

$(document).ready (function() {
$("#wfTable").dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "server/workflows",
    "bScrollInfinite": true,
   "bScrollCollapse": true,
   "sScrollY": "200px",
   "iScrollLoadGap": 50,
   "aoColumns": [
    { "sTitle": "Id",   "mData": "id" },
    { "sTitle": "Label", "mData": "label" },
    { "sTitle": "Name" ,"mData": "name" }],
    "fnDrawCallback": function (oSettings) {
        var oTable = $('#wfTable TR');
        var theData = oTable.find('TR');
        theData.unbind();
        //  On row click, go to single-view page
        theData.dblclick( function (e) {
            var iPos = oTable.fnGetPosition( this );
            var aData = oTable.fnGetData( iPos );
            var iId = aData[0];
        });
    }
});/*fnServerData  bJQueryUI true*/

//$('#wfTable').dblclick( function (e) {
/*$('#wfTable td').on("dblclick", function() {
    //target = $(e.target);

    //while(target.get(0).tagName != "TR"){
    //  target = target.parent();
    //}
    var iPos = oTable.fnGetPosition( this );
    var aData = oTable.fnGetData( iPos );
    var iId = aData[0];

    window.location.href = 'workflow/' + iId;
});*/

});

4

1 回答 1

0

我找到了这个:

    $('#wfTable').dblclick( function (e) {
    target = $(e.target);

    while(target.get(0).tagName != "TR"){
        target = target.parent();
    }

    var iPos = oTable.fnGetPosition( target.get(0) );
    var aData = oTable.fnGetData( iPos );
    var iId = aData.id;

    window.location.href = 'workflow/' + iId;
});

无论如何,您的代码也必须有效

于 2013-08-26T21:24:03.093 回答