Telerik Spreadsheet object changes values when converting to and from JSON

5 posts, 0 answers
  1. Software
    Software avatar
    7 posts
    Member since:
    Jun 2019

    Posted 31 Oct 2019 Link to this post

    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));
    });
  2. Software
    Software avatar
    7 posts
    Member since:
    Jun 2019

    Posted 31 Oct 2019 Link to this post

    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.
  3. Martin
    Admin
    Martin avatar
    224 posts

    Posted 04 Nov 2019 Link to this post

    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.
  4. Software
    Software avatar
    7 posts
    Member since:
    Jun 2019

    Posted 04 Nov 2019 in reply to Martin Link to this post

    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.

  5. Martin
    Admin
    Martin avatar
    224 posts

    Posted 06 Nov 2019 Link to this post

    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.
Back to Top