Sum of selected cells in another column

Tags: #<Tag:0x00007efc605b5c80> #<Tag:0x00007efc605b5b40>

How to get sum of selected cells in another column.

  1. i want to get sum of col1 and col2 in col3, similarly col5 is sum of col3 and col4.
  2. if i change col1 or col2 automatically update value calculate in col3 and col5
    please find js fiddle example

https://jsfiddle.net/kranthi2210/68ayj4xe/1/

Hi @kranthikumar.reddy32

There’s a little question mark in my mind right now. Do you plan to alter the SUM upon selection or have a button/switch to show the SUM of col1, col2, col3 OR col3, col4, col5, and selection does not matter?

i want based on value changes sum update in col4 and col5

OK, so a typical formula (calculation made just like in Excel) from the Formulas plugin should do the job cause they update automatically when the user changes a value in a cell. Here’s an example https://jsfiddle.net/49xetLqc/

59

Thanks for reply, i need Dynamic Configuration

Can you share a bit more details?

I am using like this https://jsfiddle.net/kranthi2210/68ayj4xe/27/ but while click on save button col4 and col5 values not getting with hot.getSourceData()

If you set up data : [], then there is no sourceData as well. If you want to start with an empty array you still need to run loadData() or hot.updateSettings({data: your_data}) to fill up the table.

Now if you prefer to calculate data from the server (and show an empty table) then you would need to use HyperFormula on the server and not as a plugin (Formulas plugin in Handsontable).

Hi Aleksandra, My query is in my table col4 is sum of col1 and col2, result is 5 as per below screenshot (1+4 is 5). but while click on save button i am calling hot.getSourceData(); but col4 value not returning. how to get the values was set by td.innerHtml

In this case, you want to pass a value to a cell renderer. However, then you cannot use the Formulas plugin. This plugin uses data (the value has to be saved).

I recommend using setDataAtCell() if you prefer to have the option to change a value of a cell, but then you’d need to run a loop for all of the cells in the column.

then how to handle.

To use the setDataAtCell() you can either provide a single cell details like,

instance.setDataAtCell(0, 1, '=A1+B1')

or create an array of details for cells and push them all in a single method, like

let changes = [[0, 4, '=A1+B1'], [0, 5, '=C1+D1'],[1, 4, '=A2+B2'], [1, 5, '=C2+D2']];
hot.setDataAtCell(changes)

Here is a demo you can test https://jsfiddle.net/hsu0m7x9/1/

ps. here’s a page in our documentation about the method https://handsontable.com/docs/javascript-data-grid/api/core/#setdataatcell