Making double click invoke the edit function

Making double click invoke the edit function

paulhickmanpaulhickman Posts: 21Questions: 1Answers: 0
edited February 2013 in Editor
I'm trying to make it so that when you double click on a row, it performs the same action as selecting that row and then clicking the edit button, but it isn't working. I'm using the fnRowCallback in the dataTable as follows:

[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$(this).bind("dblclick", function () {
self.Editor.edit($(nRow));
});
}
[/code]

I've tried using nRow and $(nRow) as the argument to edit but neither displays the correct row, and the title / buttons that are visible when you click 'Edit' are not shown in the form when it is opened in this manner. What is the correct way to pass a row to the edit() method?

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    I've suggest taking this approach, rather than fnRowCallback as it will be much more efficient (at the moment your code is binding an extra event every time the row is shown on the page!):

    [code]
    $('#tableId tbody').on( 'dblclick', 'tr', function () {
    self.Editor.edit( this );
    } );
    [/code]

    However, it is worth noting that having dblclick and click on the same element is not recommended as it is impossible to tell the difference between them. From the jQuery documentation ( http://api.jquery.com/dblclick/ ):

    > It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.

    I'd recommend one or the other approach, or possibly having a checkbox / check image in the first column which the buttons will respond to (this isn't something that is built into TableTools, yet, but it might be an option you want to consider for your table interaction).

    Regards,
    Allan
This discussion has been closed.