0

我为我的表使用插件 keyTables 和 jeditable。

我可以在网格中导航并通过返回激活 jeditable。但是如果一旦激活一个单元格,我只需单击一下单元格就可以启用 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 );
} );
} );

代码和插件是一样的。我应该只能通过单击来编辑带有返回事件的单元格。

有任何想法吗?

4

1 回答 1

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 );
            } );

会让它工作。

于 2012-11-27T19:51:23.213 回答