Issue with Enter buton

Issue with Enter buton

xfloydxfloyd Posts: 35Questions: 12Answers: 1

See this example. https://editor.datatables.net/examples/inline-editing/tabControl.html
When you click on editable cell and it turns into input, now click enter. It will save it ok. But if you now click on the cell again it will not turn into input, until you click somewhere else first. is there a fix for that. Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Hi,

    Thank you for pointing this out. The issue is related to the fact that cell has focus from the key table already. Let me look into this and get back to you.

    Regards,
    Allan

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    Answer ✓

    Yes, the issue was related to the focus. The edit that had been edited still had focus in KeyTable (not visibly in that example, but in Javascript). As such, when clicking on the cell again there was no key-focus event being triggered (it isn't needed) and thus the inline editing wasn't being activated.

    The fix is to use the following:

        // Inline editing on click
        $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline( this );
        } );
    
        // Inline editing on tab focus
        table.on( 'key-focus', function ( e, datatable, cell ) {
            editor.inline( cell.index(), {
                onBlur: 'submit'
            } );
        } );
    

    i.e. activate the inline editing on click, and also on key-focus. Although the initial click will result in both being executed, Editor will simply ignore the second one since the field is already in inline editing state.

    I'll redeploy the site with this update shortly.

    Regards,
    Allan

  • xfloydxfloyd Posts: 35Questions: 12Answers: 1

    This works great.
    Do you think you will be merging that into key plugin at some point?
    Thanks Allan

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    It probably won't be merged directly into KeyTable since I would say that KeyTable is operating as expected at the moment. The cell has focus already so it should have key-focus triggered on it again. This is simply down to the way the API is being used.

    Allan

This discussion has been closed.