Formula, columns

Tags: #<Tag:0x00007efc6542bf68>

Hello,

I apologize for this stupid question, but I can’t find any example that shows how to set up a formula in the settings.
What I am trying to do is to have something like column 3 = column 1 * column 2
column 3 being read only.

I spent a day to setup something that met my goal using custom render. it worked perfectly until I click save and realize that the value of the column were null. so I need to use a formula

Thanks for any help.

Hi @julien_vandromme

columns are identified by default by their coordinates so maybe that is why you did not find this information. Here is an example https://jsfiddle.net/hge1742x/
You can use namedExpressions to replace that with a string of your choice like here https://jsfiddle.net/6eptkcbn/

And here https://jsfiddle.net/6nd2s3u0/2/ is an example with those namedExpressions set up for column SUMs, which is what I belive the thing you were looking for. And yes… it was not easy to find that in the documentation. I will make sure to inform our team to add it.

1 Like

Thank you Aleksandra,

What if the table is empty at the beginning? and I don’t load any data, where do I set up the formula?
this is what I can’t find, all the examples comes with a data where the formula are written.

on another note, there is really nothing to do try to convert number that were calculated using a custom renderer to actual value…I understand those “value” are just “drawing” but I somehow if I could have them recognize a real value before I do a getSourceData()

basically this is what I was doing

function DecemberRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
var december = Math.round(((instance.getDataAtCell(row, col - 13) / 52)) * 10) / 10 * 5;
td.innerHTML = decemberRounded;
td.style.background = ‘#EEE’;
}

I do not know where the decemberRounded comes from but generally, you can have empty cells (here a default 5 x 5 table with empty data is loaded) with your custom code https://jsfiddle.net/bcr2whft/2/
The formula has to be attached to the cell via data (like setDataAtCell) it won’t work only for the renderer.
If you want to show a formula result without data underneath you may want to calculate those values outside the table but then you would need to create an instance of HyperFormula or use other native JS methods to make the calculations.

Hi @julien_vandromme

I hope that the lack of updates means that you solved the issue. If not, I will do my best to help.