Custom formula calculation after incremental loading finishes

Posted by: lpagliaro on 17 August 2021, 2:30 pm EST

    • Post Options:
    • Link

    Posted 17 August 2021, 2:30 pm EST

    Hi! We have some custom async functions defined that get some values from the server. And we are loading the data using incremental loading. If we try to use the custom formula while the data is being loaded in the background the formula is not evaluated. Is there a way to have the custom formula to evaluate once incremental loading finishes?

    Please refer to the following example of what I mean:

    https://codesandbox.io/s/save-load-json-custom-formula-forked-ghqfk?file=/src/index.js

    Thanks!

  • Posted 17 August 2021, 3:17 pm EST

    Actually, in the demo looks like it is working, but doesn’t work in our app. We’re trying to figure out why. We’ll add more details.

  • Posted 18 August 2021, 6:03 am EST

    Hi,

    Is there a way to have the custom formula to evaluate once incremental loading finishes?

    for this, you may use the loaded callback which gets triggered after the loaded completes. Please refer to the following code snippet and let us know if you face any issues.

    
       spreadGlobal.fromJSON(JSON.parse(jsonData), {
          doNotRecalculateAfterLoad: true,
          incrementalLoading: {
            loading: (progress) => {
              console.log(progress);
    
              sheet = spreadGlobal.getSheet(0);
    
              sheet.setFormula(4, 2, "=AsyncFunction()");
            },
            loaded: function () {
              // The works to do when loading finish.
              spreadGlobal.getSheet(0).recalcAll();
            }
          }
        });
    
    

    Further, In the sample, it seems like it is working fine after we click the load button the formula gets applied immediately. Could you please explain more about the issue so that we could have a better understanding of the issue?

    Regards

    Avinash

  • Posted 18 August 2021, 11:07 am EST

    Yes, in the example works, but not on our app. We are trying to figure out why. If we use recalcAll() it does recalculate after it loads, but is there a way to just recalculate custom formulas instead of them all?

  • Posted 19 August 2021, 12:42 am EST

    Hi,

    We are sorry but there is no method available to recalculate on a cell but you could create a method that triggers the recalculation on the particular.

    
     const load = () => {
        console.log("json", JSON.parse(jsonData));
    
        spreadGlobal.fromJSON(JSON.parse(jsonData), {
          doNotRecalculateAfterLoad: true,
          incrementalLoading: {
            loading: (progress) => {
              console.log(progress);
              if (progress === 0.4) {
              }
            },
            loaded: () => {
              let sheet = spreadGlobal.getSheet(0);
              sheet.setFormula(4, 2, "=AsyncFunction()");
              refreshCell(sheet, 4, 2);
            }
          }
        });
      };
    
      const refreshCell = (sheet, row, col) => {
        let formula = sheet.getFormula(row, col);
        if (formula) {
          sheet.setFormula(row, col, null);
          sheet.setValue(row, col, null);
          sheet.setFormula(row, col, formula);
        }
      };
    
    

    Regards

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels