This is a migrated thread and some comments may be shown as answers.

Telerik Spreadsheet object changes values when converting to and from JSON

4 Answers 29 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 31 Oct 2019, 04:57 PM

I'm trying to add custom function support for our spreadsheets. I've defined the function and I've been able to get it working as expected but sometimes I run into an issue with the sheets.rows.cells.formula field.

https://docs.telerik.com/kendo-ui/api/javascript/ui/spreadsheet/configuration/sheets.rows.cells.formula

This documentation page claims it's supposed to be a string, and if I console log it like in the code block below it behaves as expected. But if I take that JSON and try to pass it to a different file or the database to then parse back into an object and perform various operations on the data the values change. Instead of the nice sheets.rows.cells.formula being the formula string that I set, it's now turned into a function reference despite no operations being done to the data aside from converting to and from JSON. Sometimes even if I don't convert to and from JSON and just pass the object it will mutate itself inexplicably. 

Am I doing something wrong here? Why would the values change just by converting to and from JSON? I need that formula data and the function reference does not help me.

telerikDIV = kendo.jQuery('.k-spreadsheet').getKendoSpreadsheet()._workbook
 
telerikDIV.saveJSON().then((data) => {
     var json = JSON.stringify(data, null, 2);
     console.log(json);
     console.log(JSON.parse(json));
});

4 Answers, 1 is accepted

Sort by
0
Software
Top achievements
Rank 1
answered on 31 Oct 2019, 08:47 PM
Never mind, I'm pretty sure I figured it out. You can't use the json to make a new workbook object if you've already instantiated a workbook elsewhere. Seems a bit odd to me but I got it working as expected now.
0
Martin
Telerik team
answered on 04 Nov 2019, 03:24 PM

Hello,

I am glad that you were able to solve the issue as per the needs of your project.

Out of curiosity, could you please explain why are you calling the saveJSON method on the _workbook field? As far as I understand the issue, the json contains a function reference as a formula instead of the string you configured. If you look at this Dojo example, you will see that the value of the formula remains a string.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Software
Top achievements
Rank 1
answered on 04 Nov 2019, 03:45 PM

We call it on _workbook because we don't need the other fields at that stage, just need the workbook information to use later.

I found that it wasn't related to converting at all actually. If I instantiated a new kendo.spreadsheet.workbook() with the workbook that was saved it would save the formulas as a string, but if I then tried to instantiate another kendo.spreadsheet.workbook() using the same workbook json it would cause the formula strings to become function references.

The solution is to just instantiate the workbook once from the json and then pass that to each file that needs it instead of creating a new workbook reference in each file.

0
Martin
Telerik team
answered on 06 Nov 2019, 01:43 PM

Hello,

Thank you for the additional information. I hope it will be helpful to other members facing a similar issue.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Spreadsheet
Asked by
Software
Top achievements
Rank 1
Answers by
Software
Top achievements
Rank 1
Martin
Telerik team
Share this question
or