简体   繁体   中英

dataTable editable cell not responding to double click event

I have a dataTable defined as

<table id="table1"></table>

$('#table1').dataTable({
    /*definition goes here*/
});

The table is currently editable using the KeyTables plugin.

However, I want to make it editable on double click

I tried

$('#table1 tbody tr td').dblclick(function(){
    var e = jQuery.Event('keypress');
    e.keyCode = 13;
    e.which = 13;
    $(this).trigger(e);
});

However, this does not trigger the enter key event on the dataTable cell.

Well the tr in the table generated dynamically so it won't get the event binding that way, so you could use event delegation with the use of .on() method:

$('#table1').on('dblclick', 'td', function(){

This is a specific syntax for delegating the event to the closest static parent.

$(staticParent).on(event, selector, callback);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM