Is the table empty?

Is the table empty?

GeorgeHelmkeGeorgeHelmke Posts: 44Questions: 16Answers: 0

I would like to be able to know if the table is empty. Starting editor.inline(this) with no rows available ends up with a crash.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Hi,

    How are you currently adding event listeners to start the inline() edit? What you could do is modify the jQuery selector to ignore the empty row - for example:

    $('#myTable').on( 'click', 'tbody td:not(.dataTables_empty)', function () {
      editor.inline( this );
    } );
    

    Another option would be to use the data() method and check its length. If the length is 0, then there are no records in the table:

    $('#myTable').on( 'click', 'tbody td', function () {
      if ( table.data().length !== 0 ) {
        editor.inline( this );
      }
    } );
    

    Regards,
    Allan

  • GeorgeHelmkeGeorgeHelmke Posts: 44Questions: 16Answers: 0

    I went for the second option, worked perfectly. Thanks!

This discussion has been closed.