homechevron_rightStudychevron_rightMathchevron_rightAlgebrachevron_rightCombinatorics

# Tips and tricks #11: Dynamic table columns

### This page exists due to the efforts of the following people:

#### Tips and tricks series

This article may rely on knowledge you should get from previous articles, so you may want to check them first.

Using calculator editor UI, you can create output table. However, it assumes that you do know table columns in advance. If you don't you need to add them programmatically. To make it easy, table output supports column cloning operation. So, the idea is - add columns which will serve as models for your dynamic columns, hide them from final view, and use clone operation to add new columns unknown beforehand. Well, of course it is assumed that new columns somehow depend on input data. Below is the example calculator, where number of columns in the output table depends on number of rows in the input table.

Here is the code snippet. Note that it is used in the Display function of calculator, which tailors the controls, not the Calculate function, which does the calculations:

resultTable.DisplayColumn("model",false);
sets.GetValue().forEach(function(item, i) {
cloneColumn( i, item.label );
});

function cloneColumn( id, name ) {
resultTable.CloneColumn( "model","set"+id, name);
resultTable.DisplayColumn("set"+id,true);
}

Line 1 hides model column from the view.
Lines 2-4 use input object "sets" to get data and create new columns based on this data. "sets" data is array, so for each item in the array new column is created using cloneColumn function
Line 7 clones column by calling CloneColumn function on output object "resultTable", which represents, well, result table.
Line 8 shows newly cloned column.

#### Sets

arrow_upwardarrow_downwardLabelarrow_upwardarrow_downwardSet
Items per page:

Combinations

URL copied to clipboard
PLANETCALC, Tips and tricks #11: Dynamic table columns