postCreate (onPostCreate) does not seem to fire

postCreate (onPostCreate) does not seem to fire

bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

Does anyone have this problem?

I have tried the old and new name.

I init the editor with the following:

            var datatables_editor_detail_init = new $.fn.dataTable.Editor({

and add the event listener as follows:

            datatables_editor_detail_init.on('onPostCreate', function (e, json, data) {

Reference:

https://editor.datatables.net/reference/event/postCreate

This question has an accepted answers - jump to answer

Answers

  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

    Here is what I am trying to do ~ I am trying to animate or call attention to the newley created row, such as a slidein or fade in. So I want to detect the addition of the item to the table, then trigger the css.

                $("#detailTable tbody tr:last-child").css('background-color', 'lightgreen');
    
  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

    create()

    https://editor.datatables.net/reference/event/create

    Doesn't trigger either.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Hi,

    Editor should actually already flash highlight the background colour of the row using the default CSS for exactly the reason you state - to draw attention to it. You can see that effect in the examples.

    The issue here is probably that the events you mention happen before the new row has been added to the table. You'd need to do something like:

    datatables_editor_detail_init.on( 'create', function () {
      table.one( 'draw', function () {
        ...
      } );
    } );
    

    You also probably can't rely upon using tr:last-child since the sorting applied to the table might not place the row at that point.

    Sliding open a row is particularly difficult to do - if it is acceptable, use the background colour flash that Editor provides.

    Allan

  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0
    edited May 2017

    I don't understand...

    These events are not firing:

            datatables_editor_detail_init.on('onInitComplete', function (e) {
                //disable new button after init
                datatables_editor_detail_init.button(0).disable();
            });
    
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    That particular event is frankly useless now. The Editor initialisation is entirely synchronous so there is no need for it. You would do:

    var datatables_editor_detail_init = new $.fn.dataTable.Editor( ... );
    
    datatables_editor_detail_init.button(0).disable();
    

    Having said that, there isn't actually a button().disable() method in Editor! What's the goal?

    The other events such as postCreate should work though. If they aren't for you, could you link to a test case showing the issue so I can check it out?

    Thanks,
    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4
    edited March 2018

    Hi Allan,

    I have the following but the event does not fire.

            editorQuotes.on( 'postCreate', function () {
                // After create or edit, a number of other rows might have been effected -
                // so we need to reload the table, keeping the paging in the current position
                alert('New row added');
                getQuotes(); // refresh the datatable
            } );
    

    I am using

            buttons: [
                { extend: "create", editor: editorQuotes },
                { extend: "edit",   editor: editorQuotes },
                { extend: "remove", editor: editorQuotes }
            ]
    

    to create the row]
    Cheers

    Steve Warby

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    That looks like it should trigger. If you could give me a link to the page showing the issue, I can take a look into it.

    Allan

This discussion has been closed.