Altering add row from custom menu to increase numeric value from row above

Tags: #<Tag:0x00007efc6d5cd0d0>

Hi everyone!

I need help in probably something obvious. While creating new row i just need take value from cell above, and add to it 0.01. I thought just .setdataatcell will solve the problem, but i cannot make it.

    "add_row": {
      name: 'Add row',
      callback: function(key, options) {
        hot.alter('insert_row', hot.getSelectedLast()[0] + 1, 1);
        for (var i = 0; i < columns.length - 1; i++) {
            if(i===1){
               hot.setDataAtCell(hot.getSelectedLast()[0] + 1, i, hot.getDataAtCell(hot.getSelectedLast()[0],i)+0.01);
            }
           else {
                hot.setDataAtCell(hot.getSelectedLast()[0] + 1, i, hot.getDataAtCell(hot.getSelectedLast()[0],i));
            }
        }
      }
    },`

I have code like above, and i want to every first column, increase cell value with 0.01. But while it is not string its working like concat - (for example i have 1.00, adding 0.01 makes it 1.000.01) And when i have it as numeric cell type it is just not working. Any advice?

Hi @jscisinski

this

seems to be an operation on the string not a number.

I used your code here https://jsfiddle.net/x8ofm9gs/3/. does it work as planed?

  • first value in new row is duplicated
  • second is value + 0.01
  • next is empty

Your solution works great, but is any workaround about wrong adding to number 2 and 3? When you are adding value 0.01 to 3.01 makes it 3.019999999996 (and i do not have any idea why). Same for 2.01.image

The fastest way would be to add the format to numeric cells like here https://jsfiddle.net/tj42vdsk/2/. If you would like to cut only values with similar precision to 3.0199999999999996 you would need to construct a custom renderer.