To accomplish this developers must created a custom dataTable function that can be used to create this two-variable data table:
function dataTable(sheet, columnRange, rowRange, colInputCell, rowInputCell, formulaCell),
Steps to Complete:
1. Create construct of the data table
2. Create custom dataTable function
3. Apply the dataTable function
Step 1: Create construct of the data table
Create a data table construct that is in line with the two-variable being used in the data table. For this example we are trying to identify the combination of monthly payments and loan amounts so we will programmatically add a column range of numbers of months and a row range of load amounts like so:
For this sample we have added the following sample data:
Step 2: Create custom dataTable function
Next, we will create a custom dataTable function that takes the column and row range, col/row input cells, and formula cell to make the two-variable data table.
The col/row range includes the construct that was created in step 1.
The col/row input cells for the col will be where the loan amount is entered and the row input cell is where the number of months is entered.
The formula cell will be the cell of the SpreadJS instance that contains the formula that creates the monthly payments using the built-in PMT function.
Step 3: Apply the dataTable function
Finally, for this example we have added a button to the webpage that onclick the the createDataTable() function triggered and it uses the custom dataTable to set and display the two-variable data table.
With the construct and custom dataTable function applied we are able to create and see the two-variable data table displayed in the JS spreadsheet: