Calculating the average of column

Calculating the average of column

jhjhjhjh Posts: 10Questions: 5Answers: 0
edited November 2021 in Free community support

Hello, I want to implement the average value in javascript using the values imported into DB(Row1, Row2). Among the values shown in the figure, I want to obtain rows, minimum, maximum, and average values of col1 to co2, which page should I refer to?

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This example shows how to sum the column, it would be the same principle with a division in there too,

    Colin

  • jackalbrightjackalbright Posts: 14Questions: 4Answers: 0

    Colin, in the example that you point to, how do you know how many rows there are? In the original post, there are two rows. Is there a built-in function that gives us the number or rows or do you have to count them as you iterate over them?

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    edited January 2023

    @jackalbright There are a couple options.

    1. The footerCallback docs state the the data parameter is the full array of table data. You can use data.length to get the full number of rows.
    2. Using the count() API you can get the number of rows in the data set if using selector-modifier to calculate over the page or filtered data. Something like this:
    var rowCount = api
                    .column(4, { page: 'current' })
                    .data()
                    .count();
    

    Kevin

Sign In or Register to comment.