Recalculate a column after search input

Recalculate a column after search input

sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

Ok here is what I am trying to achieve...

Basically after you search for something and the results filter out, I need a column's value to change based on a formula. The grand total works fine and updates as the results change, but how can I do similar with a column that has its values calculated based off another column?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,423Questions: 26Answers: 4,794
    Answer ✓

    Possibly the drawCallback may work for you. In the callback you can write your function to recalculate the column total after every search.

    Kevin

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

    Thank you, I will look into trying that

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0
    edited February 2017

    I have successfully done the required calculations to the data using drawCallback. However at the moment I cannot find a good example for editing the column html inside this call.

     "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;                                
                                    }
                            }
    
This discussion has been closed.