jspreadsheet / ce

Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.
https://bossanova.uk/jspreadsheet/v4
MIT License
6.77k stars 828 forks source link

After edit then use function getJson to get the context, the number would be transformed to String #1390

Closed aneathesia closed 3 years ago

aneathesia commented 3 years ago

transbefore transformed How do I keep the data type unchanged?

GBonnaire commented 3 years ago

You can use event onbeforechange(element, cell, x, y, value) and return your data casted as you want

for example

onbeforechange: function(el, cell, x, y, value) {
     if(el.jspreadsheet.options.columns[x].type == "number") {
             return new Number(value);
     }

    return value;
}

code not tested

aneathesia commented 3 years ago

Your method really works, and this problem have noted in the document i missed that. note In addition, even set the column type to number but after edit the output data type will still mismatch, the problem may in this new return value type. Your code is definitely helpful.Thanks!

GBonnaire commented 3 years ago

Try with that: maybe it's new Number is not good.

onbeforechange: function(el, cell, x, y, value) {
            if(el.jspreadsheet.options.columns[x].type == "numeric") {
                    return +value;
            }

           return value;
       },

I have checked and i have good result in JSON