RowID value on create

RowID value on create

mRendermRender Posts: 151Questions: 26Answers: 13

I know I'm in the ballpark, but it seems I'm always in the ballpark haha Okay, here we go.

I need to get the row ID of a newly created row. I have the following code:

    editor
      .on( 'submitSuccess', function () {
        val = editor.val( 'projdetail.details' );   <<<<<<<<<<<<<<<<<?????
      } )
      .on( 'edit', function () {
        if ( editor.val( 'projdetail.details' ) !== val ) {
            $.post( "detail_notifications.php", { projdetid: editor.val('projdetail.projdetid') } );
        }
        } );

Now, this works when I edit a row. And I can clearly understand why. In my editor, I already have a value of that row ID. But when I create a row, that row ID is automatically created by the database, so the editor doesn't have it.

How would I go about getting that value after a successful submission?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    edited November 2014 Answer ✓

    When you create the row, the server should be returning the new id in the returned data for the Ajax request. You would then use the second parameter passed into the create method to be able to access that data.

    The second parameter passed into submitSuccess also contains that same data.

    Allan

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    Example using postCreate:

    editor.on( 'postCreate', function ( e, json, data ) {
      var id = json.row.DT_RowId; // assuming you are using DT_RowId as the id store
    } );
    

    Allan

This discussion has been closed.