Editor with edit icon not working

Editor with edit icon not working

asleasle Posts: 40Questions: 10Answers: 0

I am working on implementing my own data from this example:
https://editor.datatables.net/examples/inline-editing/editIcon.html

Here is my page.
https://wilfavarmepumpe.no/demo/Editor-PHP-2.0.7/examples/simple/simple_wilfa.html

The problem is that the edit icon shows but nothing happens when I click on the icon. It seems the <I> element is not triggering a click for the .on() function for "td I" element.

This question has accepted answers - jump to:

Answers

  • asleasle Posts: 40Questions: 10Answers: 0

    I solved it ( I think). In the example it says:

    $('#example tbody').on( 'click', 'td i', function (e) {
    

    I changed it to

    $('#example').on( 'click', 'tbody td i', function (e) {
    

    It seems it could not find the <I> with the first code. Strange?

  • kthorngrenkthorngren Posts: 15,787Questions: 25Answers: 3,739
    edited May 13 Answer ✓

    More likely there wasn't a tbody element, for the #example table, in the DOM to attach the event listener to at the time the above statement was executed. Glad you got it working.

    Kevin

  • asleasle Posts: 40Questions: 10Answers: 0

    Thanks. Yes there is a tbody tag on the table. Like the example I only wrote the thead section and datatables should create the rest, correct?

  • kthorngrenkthorngren Posts: 15,787Questions: 25Answers: 3,739
    edited May 14 Answer ✓

    datatables should create the rest, correct?

    Yes, Datatables will build the tbody. You are loading Datatables via ajax which asynchronous. The $('#example tbody').on( 'click',... is executed before the Ajax response meaning the tbody hasn't been added by Datatables yet.

    EDIT: Just to add if you have anything that needs to run after Datatables init is complete use the initComplete option.

    Kevin

  • asleasle Posts: 40Questions: 10Answers: 0

    I understand now! Thanks so much for even more enlightenment on DataTables!

Sign In or Register to comment.