Jeditable + keytables clickevent

时间:2012-11-27 11:38:19

标签: jquery jeditable

我使用Plugins keyTables并为我的表格进行了jeditable。

我可以在网格中导航并使用return激活jeditable。 但是如果激活一个单元格,只需单击一下就可以启用单元格。

出了点问题。

http://datatables.net/release-datatables/extras/KeyTable/editing.html

这是演示,工作正常。

我的小提琴: http://jsfiddle.net/jGC4J/

这是演示代码和我使用的代码:

$(document).ready( function () {
var keys = new KeyTable( {
    "table": document.getElementById('example')
} );

/* Apply a return key event to each cell in the table */
keys.event.action( null, null, function (nCell) {
    /* Block KeyTable from performing any events while jEditable is in edit mode */
    keys.block = true;

    /* Initialise the Editable instance for this table */
    $(nCell).editable( function (sVal) {
        /* Submit function (local only) - unblock KeyTable */
        keys.block = false;
        return sVal;
    }, { 
        "onblur": 'submit', 
        "onreset": function(){ 
            /* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
             * it will 'esc' KeyTable as well
             */
            setTimeout( function () {keys.block = false;}, 0); 
        }
    } );

    /* Dispatch click event to go into edit mode - Saf 4 needs a timeout... */
    setTimeout( function () { $(nCell).click(); }, 0 );
} );
} );

代码和插件是一样的。我只能用返回事件编辑一个单元格而不只是一次点击。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

简单..

添加

 $(nCell).editable('destroy');

/* Apply a return key event to each cell in the table */
            keys.event.action( null, null, function (nCell) {
                /* Block KeyTable from performing any events while jEditable is in edit mode */
                keys.block = true;

                /* Initialise the Editable instance for this table */
                $(nCell).editable( function (sVal) {
                    /* Submit function (local only) - unblock KeyTable */
                    keys.block = false;
                    // INSERT HERE //
                    return sVal;
                }, { 
                    "onblur": 'submit', 
                    "onreset": function(){ 
                        /* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
                         * it will 'esc' KeyTable as well
                         */
                        setTimeout( function () {keys.block = false;}, 0); 
                    }
                } );

                /* Dispatch click event to go into edit mode - Saf 4 needs a timeout... */
                setTimeout( function () { $(nCell).click(); }, 0 );
            } );

会让它发挥作用。