Parent / child editing with Editor doesn't store parent id

Parent / child editing with Editor doesn't store parent id

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0
edited January 2017 in Free community support

Hello,

I used this example https://datatables.net/blog/2016-03-25 and when I create a new child entry the new chield entry doesn' store the parent id. This makes the link between parent and child entry impossible.

Is it a common bug or did I something wrong? Should I post my complete source code?

Kind regards

Patrick

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    edited January 2017 Answer ✓

    Parent Child works. Please post your code for review.

    One key area is to have the child table setup with the properly for the ajax post. For example.

    ```
    ajax: {
    url: '/your_url_here',
    type: 'post',
    data: function ( d ) {
    var selected = table.row( { selected: true } );

                    if ( selected.any() ) {
                        d.pkid = selected.data().main.pkid;
                    }
                }
            },
    

    ```

    Kevin

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Answer ✓

    The other key part, in addition to what Kevin has mentioned, is where the default is set for the child Editor, which it sounds like might be missing from your own code:

        usersEditor
            .field( 'users.site' )
            .def( siteTable.row( { selected: true } ).data().id );
    

    That will set the value that will be submitted when the new row is created.

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Perfect I got it :-)

    My bug was here:
    .field( 'users.site' )
    I thought that users is linked to this table
    <table id="users" ...>
    but it the link to mysql table (where I changed the name).

    Thank you both very much

    Patrick

This discussion has been closed.