Percentage column support in handsontable

Tags: #<Tag:0x00007efc71a0d3d0> #<Tag:0x00007efc71a0d240>

In Handsontable if user input number concat with percentage symbol (i.e. 10%) in a cell in percentage column then formula associated with it calculate properly but in percentage column it shows error
can u please help me this use case?

Hi @siddhantjain15298

This is the simplest form of the task that I created here https://jsfiddle.net/d83ztnwa/ with formulas, with one cell dependency, and a custom renderer to attach the % char. Could you please tell me how did you proceed with this task in your project?

Hi
My use case is different

  1. if user input number like this “30%” in the cell then it should be calculated in formula like number*0.3 accordingly

To be sure I understand correctly, could you please share input and output data but also the mentioned formula involvement? Changing 33% to 0.33 could be done also by a custom cell renderer (if ‘33%’ still has to be held in the data) with the use of replace() and division of the value as in https://jsfiddle.net/tzv7308m/. But if you want to replace that 33% to 0.33 and not only to show to like this to user, but also to be calculated in a formula you would need to replace the value, for example using setDataAtCell().

In the Hyper formula, we have a formula that includes percentages that can accept value in number and Number%
If it is a number we need to update the number /100 in the formula but if the user inputs number% then we do nothing.
Can we achieve that in handsontable formulas?

Now, in formula plugin the % works well. If we use

const data = [
  {'id': 1, points: 134, score: '=A1*50'},
  {'id': 2, points: 155, score: '=A2*66%'},
  {'id': 3, points: 98, score: '=A3*53%'}
]

we get

40

Demo for tests: https://jsfiddle.net/j864fdgp/

But if you would like to make C1 =A1 * 50% that triggers another question - would that % apply no any numeric value? I can imagine that we can add it no any numeric value that does not have a letter (cell coordinate), but would that meet your project requirements?

Can we manage it in handsontable whenever user input number in percentage column then formula would calculate like this percentageValue/100 and if user enters percentage value in {number}% then formula remain as it is ?
for your reference:
C1 =A1*50/100; C2 and C3 it remain as it

I am not sure if that will help, as I do not know if that covers all your use cases. But if we always used the number as a last one maybe we can use the endsWith() method like so https://jsfiddle.net/d5w3a80u/. Would that work for you?

Hi
Formulas are in the form of =A1*B1
And B1 value is a percentage column where there are 2 scenarios where the user can input a {number} as well as {number}% I don’t think the above example works in this case
can you please check if this is achievable
Thanks

Yes, that makes this example unusable. :sweat_smile: we’d need to add a check to the second cell reference. Is that always one_cell * second_cell? Or you can have +, -, etc. operators + more than 2 references included?

No It can anything
This is just an example
basically i want to make second reference column (B1 used in above example) conditional based on percentage value

If that can be anything in that formula I recommend changing the percentage column logic then, so if user type 50 there you change it to 50% after the formula is calculated.

Hi
If that is possible how can we achieve this ?
Thanks

Please check if this will work https://jsfiddle.net/w21xh6r0/. It only checks if percentage column has a % and if not it adds it before the formula in the last column is calculated.

Hi, We are using handsontable v12.1.0 whenever i am changing 55% to 55 then it renderer properly but in the formula it is showing 55 instead of 0.55.
here is the link: https://jsfiddle.net/w21xh6r0/
Can u please help me?
Thanks

Is that a correct demo? When I change 55% manually to 55 and close the editor the value in the last column is correct 48,2 which comes from 0.55*4+(23/0.5). And the value in the Percentage column is altered to be 55%.