How to refresh table #2 when table #1 has been edited?

How to refresh table #2 when table #1 has been edited?

monkeyboymonkeyboy Posts: 60Questions: 19Answers: 0

I have a subtotals table and a details table. I need to force a redraw of the subtotals table after any cell in the details table has been edited. (The server updates the subtotals table by using post edit events to call an update function)

``` var subtotalsTable;
$(document).ready(function() {

        myEditor = new $.fn.dataTable.Editor( {....

           var detailTable = $("#detailTable").DataTable( {
        "drawCallback": function( settings ) {
            subtotalTable.draw();
        }, ........

            subtotalTable = $("#subtotalTable").DataTable( { .....

```

I have an apparent scope issue - subTotalTable is undefined (in javascript console)
I tried to declare my subtotalTable variable as a global, but this did not work.

Any help would be much appreciated!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    We'd really need to be able to see the full code to understand if what the scoping issue is. However, it might actually be an ordering issue - if it is executed in the order shown above, then the draw callback will happen before you have defined the subtotalTable variable, resulting in the error you are seeing.

    Perhaps a simple if ( subtotalTable ) in your draw callback would be all that is needed in this case.

    Allan

  • monkeyboymonkeyboy Posts: 60Questions: 19Answers: 0

    Allan,
    Thanks so much! Function ordering took care of the problem. ajax.reload (and not draw) is also needed to make this work correctly

This discussion has been closed.