Retrieve value of newly created row

Retrieve value of newly created row

crush123crush123 Posts: 417Questions: 126Answers: 18
edited October 2015 in Editor

With editor 1.4, I managed to do this in my ajax page, using the code below...

if ( isset($_POST['action']) && $_POST['action'] === 'create' ) {

$rowid = ltrim($data['row']['DT_RowId'],'row_');

}

Now i am using 1.5.1, this doesn't work for me anymore.

I have tried followng the example and this post...
https://datatables.net/forums/discussion/25609/retrieving-the-mysql-id-for-a-newly-created-row

but i can't seem to get the syntax right.

would appreciate any help

This question has an accepted answers - jump to answer

Answers

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    Ok, fumbled may way to it

    for 1.5.1, the syntax i used is

    $rowid = ltrim($data['data'][0]['DT_RowId'],'row_');
    
  • ThomDThomD Posts: 334Questions: 11Answers: 43

    1.5 added support for multiple updates. I think the "legacyajax" option adds support for the previous syntax, based on a single record update.

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited October 2015

    Thanks Thom

    I did see that, but wanted to update to the new syntax.

    the solution I offered in the second post works ok for create, but now i am having trouble with delete.

    on my ajax source page, i want to delete rows from a related table when a row is removed from my parent table. with 1.4 it was straightforward

        if ( isset($_POST['action']) && $_POST['action'] === 'remove' ) {
    
    //retrieve value(s) from editor and format as a comma separated string
    $rowid = ltrim(str_replace('row_',',',implode($_POST['id'])),",");
    }
    

    with 1.5, i have tried using a php array function to get the key and extract the row id from that

        if ( isset($_POST['action']) && $_POST['action'] === 'remove' ) {
        $rowid = array_keys($_POST['data']);
      ....
    }
    

    Is that the best way ?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Server-side events in 1.5 might actually be the best way.

    Alternatively you could parse the new data format (as you are doing) and that will also work - so yes, the array_keys method you have used is the best way if you want to do it like that.

    Allan

This discussion has been closed.