Skip to content

How spreadsheets are managed

Robert Plummer edited this page Aug 8, 2014 · 2 revisions

Inside jQuery.sheet there are some seemingly complex mechanisms to calculate numbers. Here we attempt to break them down.

The element structure:

table <-- repeats for every spreadsheet colGroup col <-- repeats for every column in spreadsheet tBody tr <-- repeats for every row in spreadsheet td <-- repeats for every column in spreadsheet row

jQuery.sheet object structure:

$.sheet.instances //<-- contain all instances of jQuery.sheet
$.sheet.instances[0].spreadsheets //<-- contain all spreadsheets of the first instance of jQuery.sheet
$.sheet.instances[0].spreadsheets[0] //The first spreadsheet in said instance
$.sheet.instances[0].spreadsheets[0][1] //The first row
$.sheet.instances[0].spreadsheets[0][1][1] //The first cell, equivalent to =Sheet1!A1

How does dependency and cell updating happen?

  • Essentially when a cell is parsed, it has a property dependencies{Array}, with each of the values are the dependent cells.
  • Any time a value of a cell is needed, we use the calcLast{Date} property both on the cell and on the jQuery.sheet instance to find when it was last updated.
  • Call jS.updateCellValue on the cell, when the value is static, we return that, otherwise if the value is made up from a formula we: ** If calcLast is up to date, no action is taken, just return the value (or resolved value from a formula that is cached in the cell) of the cell ** If calcLast is not up to date, we set it to the current calcLast for the spreadsheet ** Empty the dependency array ** Parse the formula, when a cell is found in the forumla we add that to the dependency property ** Before resolving the formula, we update the dependent cells using updateCellValue, update their calcLast, and so the recursion continues until a result is found ** updateCellValue returns the updated value recursively

This is due to change somewhat in 4.0, when it is released.

Things to keep in mind: Cell values will only be resolved once during a calc.

Clone this wiki locally