How to get Events to Work???

How to get Events to Work???

elcidelcid Posts: 5Questions: 2Answers: 1
edited February 2016 in Free community support

I've looked through the documentation, examples and forum posts and for the life of me cannot get events to work!

For info I am using the DataTables Editor...

I am trying to setup an event listener for when there is a new record or an edit within a given datatable.

The closest I can get for it to work is the following which fires off everytime the grid display changes:

<script type="text/javascript">
$(document).ready(function() {
    $('#t_entities').on( 'draw.dt', function () {
        alert( 'Table redrawn' );
    } );
} );
</script>

For example I've tried this:

editor.on( 'create', function ( e, json, data ) {
    alert( 'New row added' );
} );

editor.on( 'edit', function ( e, json, data ) {
    alert( 'Edit row' );
} );

None of it works! I dont know whats missing but I cant get any of the new commands/api to work i.e.https://editor.datatables.net/manual/events which is in the format function function( e, json, data ) ...

It would be great to see much more examples for managing events...

All I need is the basic example here: https://editor.datatables.net/examples/simple/simple.html whereby the event is captured for new records and edited records i.e. alert box (which I can use as a starting point to implement my code which needs to leverage these events as the trigger)...

I really appreciate some help on this one!

Cheers,

Sid

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Hi Sid,

    This example shows how events might be used with Editor.

    What you have above looks like it should work perfectly well - can you give me a link to the page you are working on so I can take a look as there is obviously something else going wrong here. Is the row being correctly added to the table after being created / edited?

    Allan

  • elcidelcid Posts: 5Questions: 2Answers: 1
    edited February 2016

    Hi Allan,

    Appreciate the quick reply! Indeed I've managed to get this working....

    I placed the code in between the table.<name>.js file located in the PHP folder and it works as per your example... Prior to that I had it at the bottom of my main file and it didn't work despite the reference to the .js file...

    The thing that really caught me out is my browser which required a clear on the cache... Once done the code worked but only in the .js file... I'm using firefox and it seems no matter how I try to set it up with not caching etc - it still does it and messes up viewing code changes... Older versions of firefox didn't do this...

    So a lesson to be learned to all concerned double check with clearing browser caching, before banging your head against the wall lol ;-)

    Allan - thanks again for the double check it was re-assuring to know that I was in the right direction...

    Cheers,

    Sid

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Hi Sid,

    No worries and good to hear you've got it working now!

    Allan

This discussion has been closed.