Counting the sum of the values of cells

@ann62042
Counting in a table isn’t hard.
Here is the solution:

First add a table and connect it to a dataset.
Make sure you have an extra field named sum without any data in your dataset

Then use the following code


$w.onReady(function (){
    $w("#dataset1").onReady(()=>{
        var tableRows = $w("#table1").rows
      for (let i = 0; i < tableRows .length; i++) {
          tableRows[i].sum = tableRows[i].number1 + tableRows[i].number2
      }
      $w("#table1").rows = tableRows
    })
})

Kind regards,
Kristof.

2 Likes

@volkaertskristof Hey Kristof, thanks, but I don’t actually have a table. It is all in a database. I have a set of radio button inputs, each with different values for their options. Those get stored in the database, and I need an extra column that is the sum of all responses.

Hi Ann,
Make a new post .
Add your code and images of what you are trying to do

@volkaertskristof Hey Kristof, biggest thanks for this. This is exactly what I need. Can you tell me just one thing - why it only shows 12 fields with this code? I have 100 and they’re not showed. Hope you can help, best regards!

Hi Tamara,
Go to your dataset that you added to your page and check the settings. It will probably have a limit of 12, change it to 100 or more, i think 999 is the max.

1 Like

@volkaertskristof You’re great! That solved the problem :slight_smile: Also, I made an admin panel for boxing judges so that they can insert if someone won or lost the match and I want to update the database with that data. I put two radio buttons to make it simple for them to use. So if they click “won” button I would like to increase “wins” field with +1 and save that in database or if they click “lost” to increase field “loses” with +1 for the specific player. Is that possible? Thank you one more time, you’re awesome! :slight_smile: