footerCallback calculatte average...

footerCallback calculatte average...

BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0
edited January 2022 in DataTables 1.10
, "footerCallback": function (row, data, start, end, display) {
                                                var tdailyPI;
                                                var api = this.api(), data;
                                                //function to convert string values to numeric
                                                var intVal = function (i) {
                                                    return typeof i === 'string' ?
                                                        i.replace(/[\$,]/g, '') * 1 :
                                                        typeof i === 'number' ?
                                                        i : 0;
                                                }
                                                //Total Qty
                                                if (api.column(5, { search: 'applied' }).data().length > 0) {
                                                    avgPI = api
                                                                .column(5, { search: 'applied' })
                                                                .data()
                                                                .reduce(function (a, b) {
                                                                    return intVal(a) + intVal(b);
                                                                }, 0);
                                                    //totWd = time_convert(totWd);
                                                    //totWd = $.fn.dataTable.render.number('', '.', 2, '').display(totWd);

                                                    avgPI = convertNumToTime(avgPI);
                                                    tdailyPI = avgPI;
                                                    //totWd = $.fn.dataTable.render.number('', '.', 2, '').display(totWd);
                                                }
                                                else {
                                                    avgPI = 0.0;
                                                    tDailyPI = avgPI;
                                                }
                                                //totWd = (totWd * 0.6);
                                                //totWd = time_convert(totWd);
                                                //totWd = $.fn.dataTable.render.number('', '.', 2, '').display(totWd);
                                                $(api.column(5).footer()).html(avgPI);
                                                //Daily PI

                                            }

//I WANT TO CALCULATE AVERAGE OF avgPI with search effect...

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0

    Colin, I just wanna know how to get total number of rows with search effect..

    $(api.column(5).footer()).html(avgPI);
    here, avgPI should be divided by total no of rows with search effect if user searched for anything, if not given search, avgPI should be divided by total nos of rows..

    Thanks,
    ßhavin.

  • kthorngrenkthorngren Posts: 20,255Questions: 26Answers: 4,761

    I just wanna know how to get total number of rows with search effect..

    Use something like this:

    var numRows = api.rows({search: 'applied'}).count();
    

    See the selector-modifier and count() docs.

    Kevin

Sign In or Register to comment.