Object or model data #994
IcepiQ
started this conversation in
API Questions
Replies: 1 comment 1 reply
-
Hi @IcepiQ, HyperFormula is a spreadsheet engine, so it operates on arrays, not objects/models. For integration with Kendo UI you need to convert your models to arrays and after calculation convert it back to models. Here is an example of how you can achieve it: // Define the props of your models
const ALL_MODEL_PROPS = ["Name", "Year_1", "Year_2", "Avg_1", "Sum_1"];
// Conversion functions
function modelToArray(model) {
return ALL_MODEL_PROPS.map((prop) => model[prop]);
}
function arrayToModel(array) {
const entries = ALL_MODEL_PROPS.map((key, index) => [key, array[index]]);
return Object.fromEntries(entries);
}
// Define your data as an array of models
const sourceModelData = [
{
Name: "Greg Black",
Year_1: 42,
Year_2: 24,
Avg_1: "=AVERAGE(B1:C1)",
Sum_1: "=SUM(B1:C1)"
}
//...
];
// Pass data to HyperFormula
hf.setCellContents(
{
row: 0,
col: 0,
sheet: sheetId
},
sourceModelData.map(modelToArray) // the conversion happens here
);
// Get calculated values back from HyperFormula and convert it back to models
const resultModelData = hf.getSheetValues(sheetId).map(arrayToModel);
console.log(resultModelData); HandsontableYou can also check out the Handsontable grid. It supports formula calculation of out the box by using HyperFormula internally. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to load an object/model as data into hyperformula but the setCellContents won't allow it, is there a different way to load this sort of data?
The reason I need the mode/object is because I want hyperformula to do calculations then send the output to a kendo ui grid which requires model data.
According to your documentation hyperformula is supposed to integrate with grids such as Kendo Grid UI, do you have documentation on how to achieve this?
If I have this model which I adapted from your demo:
Regards
Raff
Beta Was this translation helpful? Give feedback.
All reactions