From 0,00 (with comma) to 0.00 (with dot) when pasting

Tags: #<Tag:0x00007efc6b8c4178>

Hi,

I have a problem. My handsontable will receive many copy-paste numbers from other Excel files. These numbers can be in 0.00 format or in 0,00 format (with comma), but when they are pasted on my handsontable they have to ALWAYS appear in 0.00 format (with dot). I have thought of using the “beforePaste” event to convert 0,00 to 0.00, but this event DOES NOT WORK, it is not even introduced by the function of the event.

Now I have the numeric type and the format to 0.00. This causes that when I do copy-paste the following happens:

100 —> 100.00 OK
100.45 —> 100.45 OK
100,45 —> 10045 KO

Please, how would you solve this problem? Why does not the “beforePaste” event work?

Greetings.

Hi @carlos.duran.garcia

currently, your copied value needs to follow the pattern provided by format settings for numeric type. Here is an example http://jsfiddle.net/handsoncode/g9nud41w/
we have 3 values

70.50
70,50
70,500

and only the last one will give us the same value after paste as it follows the rule of format: '$0,000'

I understand that this can be overwhelming in some cases but this is how Numbro works (the library that we use to handle numeric cells) and it would be pretty hard to change it as in some cases your format may have a dot and a comma that complicates the situation, like here http://jsfiddle.net/handsoncode/c9fxj3zv/ where the first value is the same this time and the rest gives us different values.

Please read docs Numbro > format for more information

Can you share your code whee you replace a comma to a dot and the beforeChange does not do the work?

Thanks in advance.

Hi,

My “beforePaste” function is nothing special. I have simply copied the one that comes in the Handsontable documentation and I have put “console.log” to see what information they contain. The method is not even executed when I paste the information.

var tablaIngresosSettings = {
data: oData,
...
maxRows : dataLength,
beforePaste: function(data, coords) {
	// data -> [[1, 2, 3], [4, 5, 6]]
	console.log(data);
	console.log(coords);
	// data -> [[4, 5, 6]]
	// coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
},
cell: cellSettings,
fixedColumnsLeft : 4,
columnSummary: columnSummarySettings

};
new Handsontable(htmlTabla, tablaIngresosSettings);

My idea is to use the “beforePaste” event to change the 0,00 values to 0.00. In order to do this, the numbers copied in the parameter “data” must be able to be modified.

Is it possible to do this?

Thank you and greetings.

If this is not executed there has to be some kind of problem before this statement. I have added this callback and the two logs here http://jsfiddle.net/handsoncode/2n4zz474/ where it works as expected.

Here is an example where I use beforePaste to change a value that has a comma to one with a dot. As I said before it is easy when you only have a comma or a dot, in other cases it may be harder to do: http://jsfiddle.net/handsoncode/r2wtdrpq/