Editor with submitOnBlur and serverSide fails

Editor with submitOnBlur and serverSide fails

derkanderkan Posts: 6Questions: 1Answers: 0

Hi,
submitOnBlur with serverSide fails with(after data is submitted):

TypeError: idx is undefined
var col = dt.settings()[0].aoColumns[ idx.column ];

I couldn't build a test environment at DataTables JS bin, as editor is not included at that site.

Regards,
Erkan D.

This question has an accepted answers - jump to answer

Answers

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

    Hi Erkan,

    Thanks for your question. This should actually work - on this page if you open your browser's console and enter:

    $('#example').on( 'click', 'tbody td', function () {
      editor.inline( this, { submitOnBlur: true } );
    } );
    

    it will effectively enable inline editing for that table. If you do so, are you able to reproduce the issue you are seeing? It appears to work okay for me.

    Thanks,
    Allan

  • derkanderkan Posts: 6Questions: 1Answers: 0

    I forgot to mention that I'm using inline editing mode. Can you check it please?
    Thanks

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

    The code I noted above uses inline editing - it specifically called the inline() method on the second line.

    Allan

  • derkanderkan Posts: 6Questions: 1Answers: 0

    Allan,
    On editor examples at "Inline Editing" section, all examples (for example this )includes following code:

        // Activate an inline edit on click of a table cell
        $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline( this );
        } );
    

    The example you mentioned is using tabletools to open a dialog for editing.

    Regards

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

    Hi,

    Yes - as I noted above, you would need to open your browser's console to run the code above. That will effectively turn the server-side processing demo into an inline editing demo that uses server-side processing.

    That is the configuration you noted that you were having a problem with, but I've been unable to reproduce the issue.

    Are you able to give me a link to your page so I can just debug it directly?

    Thanks,
    Allan

  • derkanderkan Posts: 6Questions: 1Answers: 0

    Thanks for response. My example was also using tab navigation. On console I run this following code and than try tabbing on inline edit, I got error:

    TypeError: h is undefined
    ..."node"]());if(c){if(b)f=c[b];else{var b=e["settings"]()[0][("a"+"o"+"Co"+"l"+"...
    

    I think this is the same error.

    Code:

    $('#example').on( 'click', 'tbody td', function () {
      editor.inline( this, { submitOnBlur: true } );
    } );
    editor
            .on( 'open', function ( e, type ) {
                if ( type === 'inline' ) {
                    // Listen for a tab key event when inline editing
                    $(document).on( 'keydown.editor', function ( e ) {
                        if ( e.keyCode === 9 ) {
                            e.preventDefault();
     
                            // Find the cell that is currently being edited
                            var cell = $('div.DTE').parent();
     
                            if ( e.shiftKey && cell.prev().length && cell.prev().index() !== 0 ) {
                                // One cell to the left (skipping the first column)
                                cell.prev().click();
                            }
                            else if ( e.shiftKey ) {
                                // Up to the previous row
                                cell.parent().prev().children().last(0).click();
                            }
                            else if ( cell.next().length ) {
                                // One cell to the right
                                cell.next().click();
                            }
                            else {
                                // Down to the next row
                                cell.parent().next().children().eq(1).click();
                            }
                        }
                    } );
                }
            } )
            .on( 'close', function () {
                $(document).off( 'keydown.editor' );
            } );
    

    Regards,
    Erkan D.

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

    Hi Erkan,

    Thanks for the additional information that you are using the tabbing navigation.

    Since that is the case I would suggest modifying

    editor.inline( this, { submitOnBlur: true } );

    to be:

    editor.inline( table.cell( this ).index(), { submitOnBlur: true } );
    

    where table is the DataTable instance.

    The reason it won't work with a node being passed in is that after a redraw the original node you give it has been removed from the document. Passing in the cell index will allow it to work.

    Allan

  • derkanderkan Posts: 6Questions: 1Answers: 0
    edited June 2015

    Thanks Allan, your suggestion solved the problem!
    Regards,
    Erkan D.

This discussion has been closed.