modify cell values via drawCallback?

modify cell values via drawCallback?

sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

I have successfully done some data calculations via the drawCallback function in the API per the suggestion of another user here. However I cannot seem to figure out how to modify the cells I need with the new data. Here is my function which works and logs the calculations to the console...

"drawCallback": function (settings) {
                           var api = this.api();                                            
                           var myData = api.rows({ page: 'current' }).data();                     
                           var z = $("#sct_size_wrapper > div > div > div > table > " +
                               "tfoot > tr > td:eq(3)").html();
                               z = z.split(',').join('');               
                               for (var i = 0; i < myData.length; i++) {                               
                                   var y = myData[i][3];
                                   var result = parseFloat((y / z) * 100);
                                   result = result.toFixed(2);
                                   console.log(result);
                                   myData[i][4] = result;                               
                               }
                       }

Any help or tips would be appreciated!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,919Questions: 26Answers: 5,066
    Answer ✓

    Maybe you need to add api.rows({ page: 'current' }).invalidate(); between lines 13 and 14. This should cause the table to refresh.

    Kevin

  • allanallan Posts: 64,311Questions: 1Answers: 10,621 Site admin

    Is it the footer that you want to insert the data into? Or a cell in the tbody?

    Allan

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

    cell in tbody

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

    @kthorngren, thank you so much! Your suggestion worked perfectly...you have saved me a LOT of time and trouble!

This discussion has been closed.