Editor - Uncaught TypeError: Cannot read property 'contents' of undefined

Editor - Uncaught TypeError: Cannot read property 'contents' of undefined

pckopatpckopat Posts: 7Questions: 2Answers: 0

i use inline editing. When i edit a cell and then click outside of table, there is not problem. But if i click another cell after edit, it give 'Uncaught TypeError: Cannot read property 'contents' of undefined' error. In the video you can see what I mean.

https://www.youtube.com/watch?v=lycpnBBQd4o

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Are you using Editor 1.5.3 (the current latest release)? Also, could you give me a link to the page so I can debug it please.

    Thanks,
    Allan

  • pckopatpckopat Posts: 7Questions: 2Answers: 0
    edited December 2015

    Yes i use editor 1.5.3.
    i send the link via private message

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Super - thanks for the link! The issue is the combination of inline editing and server-side processing - they can be used together, but we just need to be a little careful with how we call the inline() method. At the moment you have:

                $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
                    editor.inline( this, {
                        onBlur: 'submit'
                    } );
                } );
    

    The issue there is that after the submit the table will be redrawn and the cell that was clicked on (this) no longer exists - hence the error.

    The way to fix is fairly easy, we just give Editor the cell index rather than the cell node:

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

    The index is still value after the redraw so this will work.

    You also need to change $('#example').DataTable( to be:

    var table = $('#example').DataTable(
    

    Regards,
    Allan

  • pckopatpckopat Posts: 7Questions: 2Answers: 0

    Thank you so so much. You are a hero.

This discussion has been closed.