Update data of different table on postEdit/postCreate

Update data of different table on postEdit/postCreate

Red SniperRed Sniper Posts: 52Questions: 11Answers: 0
edited May 2022 in Free community support

Link to test case:
can provide, on request and privately, link to page in my dev environment

Description of problem:
In a page I have 3 tables (A , B , C).
When I edit (or create a new ) line in table A, I need to update a specific column of a row in table B, with the sum of the values of a column in table A..
I have tried with postEdit and postCreate events, but the sum I get by iterating each table As' rows are the old ones (before the data is being updated in dt).

Am I using the wrong event ? Should I use something else ?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    It would be worth using submitComplete for that - see example here. This is summing the "Age" column in the first table and adding it into the second - this is the relevant code:

      editor1.on('submitComplete', function() {
        var total = table1.column(3).data().reduce(function(a,b) {
          return parseInt(a) + parseInt(b)
        }, 0);
        
        editor2.edit(0, false).set('total', total).submit();
      });
    

    Colin

  • Red SniperRed Sniper Posts: 52Questions: 11Answers: 0

    Hi Colin,

    thanks for that .
    I haven't used submitComplete because reading the doc I thought it was related to ajax sourced datatables only,

    best regards

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

    It's when the submission completes. Are you using Ajax? If not, how are you sending the data back to the server?

    Colin

  • Red SniperRed Sniper Posts: 52Questions: 11Answers: 0

    I am not using ajax.
    In our program there is no "live" inserting/editing, therefor all save/insert of records are done when the user confirms the operation.

Sign In or Register to comment.