Refresh child row when parent row updated

Refresh child row when parent row updated

penguinolpenguinol Posts: 5Questions: 3Answers: 0

Hello, I have a simple datatables editor going and I'm trying to figure out how I can refresh a child row after updating the parent row's data. I assume I need to somehow either re-call/show the child row, but not sure how to do that. Thanks.

                   var editor = new $.fn.dataTable.Editor( {
                                    "ajax":{
                                            url:"php/table.php",
                                            type:"POST",
                                            data: function ( d ) {
                                                    d.is_date_search = $is_date_search; 
                                                    d.start_date = $start_date;
                                                    d.end_date = $end_date;
                                            }
                                    },
                            table: '#table',
                            fields: [
                                    {
                                            "name": "patients.patientID",
                                            "type": "hidden"
                                    } ,
                                    {
                                            "label": "atty id",
                                            "name": "patients.atty"
                                    }
                            ]
                    } );

        $('#table tbody').on('click', 'td.details-control', function () {
                var tr = $(this).closest('tr');
                var row = table.row( tr );

                if ( row.child.isShown() ) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
                }
                else {
                // Open this row
                row.child( format(row.data()) ).show();
                tr.addClass('shown');
                }
        } );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    You are correct - you'd basically need to do

    row.child( format(row.data()) ).show();
    

    again. You could do that in a postEdit event handler - e.g.:

    editor.on('postEdit', function (e, data, json, id) {
      var row = table.row('#'+id);
      if (row.child.isShown()) {
        row.child( format(row.data()) ).show();
      }
    });
    

    Allan

  • penguinolpenguinol Posts: 5Questions: 3Answers: 0

    You're awesome, thanks Allan!

This discussion has been closed.