homechevron_rightStudychevron_rightMathchevron_rightGeometry

Tips and tricks #10: Dynamic table columns

This article describes how to work with dynamic columns in your calculator

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.

PLANETCALC, Combinations generator

Combinations generator

Sets

LabelSet
Items per page:

Combinations
 
Combinations
Save the calculation to reuse next time, to extension embed in your website or share share with friends.

Comments