2012-11-27 25 views
0

我使用插件keyTables和jeditable为我的表。Jeditable + keytables clickevent

我可以在网格中导航并用返回激活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); 
}); 
}); 

的代码和插件是相同的。我应该只能通过返回事件来编辑单元格,而不仅仅是单击一下。

任何想法?

回答

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

将使它发挥作用。