Parent / child editing: Parent table needs to show child table information

Parent / child editing: Parent table needs to show child table information

szakendreszakendre Posts: 24Questions: 10Answers: 0

Hello!

I made a parent / child solution based on this example:
https://editor.datatables.net/examples/advanced/parentChild.html

The parent table shows the order projects, the child shows the elements of the choosen order.
Each element has price and quantity.
How can I show the summarized price of elements on the parant table?

ajax:
{
    url: 'ajax/pr1.php',
    type: "POST"
}
    $editor = Editor::inst( $db, 'pr', 'id' )
    ->fields(
...
);
$editor->process( $_POST );
$editor->json();

Thank You and best regards:
Endre, Szak

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Are you looking for something like the FooterCallback example? If so you can change it to sum the columns of the child table instead of the parent.

    Kevin

  • szakendreszakendre Posts: 24Questions: 10Answers: 0

    Hi Kevin,

    I need a different solution. For the summary value I have to run an SQL query on the server side.
    If I have the variable, how can I modify the AJAX answer to send this extra information? I mean can I insert a plus variable to POST data?

    Thanx

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    You can use the ajax.data option to send extra info. Guessing you want to run the SQL query when fetching the child table? If so add it here (from the example you linked):

        var usersTable = $('#users').DataTable( {
            dom: 'Bfrtip',
            ajax: {
                url: '../php/users.php',
                type: 'post',
                data: function ( d ) {
                    var selected = siteTable.row( { selected: true } );
                    if ( selected.any() ) {
                        d.site = selected.data().id;
                    }
                    d.extra_info = myVariable;
                }
            },
    

    Kevin

  • szakendreszakendre Posts: 24Questions: 10Answers: 0
    edited July 2020

    Hello Kevin,

    Thank you, this part is working, I can send extra variable from JS to PHP.
    Now I have to send extra datas from PHP to JS.
    Do you have any idea how to do that?

    Thank You and best regards:
    Endre, Szak

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    This thread here might help, it's showing that,

    Colin

  • szakendreszakendre Posts: 24Questions: 10Answers: 0

    I couldn't solve the problem with this method, so I did a workaround:

    With postCreate and postEdit I made a function that update the datas of the parent table. Then I force a reload upon any changes, so it did the trick.

    Thank you!

This discussion has been closed.