How can I properly arrange the order of options in the Column Switcher without changing the actual order of fields in a DataTable?
In the provided JSL, simply sorting the list of columns does not affect the order of options in the Column Switcher.
I have noticed that sometimes the actual order of columns in the DataTable can affect the order of options in the Column Switcher, but other times it does not (I do not know the reason). However, when working with a DataTable that has many columns, changing the order of the columns is very time-consuming and seems meaningless. Is there a way to achieve the desired sorting of options in the Column Switcher without changing the actual column order?
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column( "Column 0", formula( :weight+1 ) );
dt << New Column( "Column 14", formula( :weight+2 ) );
dt << New Column( "Column 3", formula( :weight+3 ) );
dt << New Column( "Column 2", formula( :weight+4 ) );
dt << New Column( "Column 11", formula( :weight+5) );
dt << New Column( "Column 1", formula( :weight+6 ) );
dt << New Column( "Column ", formula( :weight+7 ) );
col = dt << get column names( string );
SwitchOption = {};
For Each( {value, index}, col,
If( Word( 2, value, " " ) != "",
SwitchOption = Insert( SwitchOption, col[index] )
)
);
//The column list before the order arrangement.
Graph = Graph Builder(
Size( 534, 464 ),
Show Control Panel( 0 ),
Variables( X( :name ), Y( :Column 0 ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);
Graph << Column Switcher(
Column( "column 0" ),
SwitchOption,
Title( "Test" )
);
//The column list after the order arrangement.
orderedSwitchOption = {};
oder = {};
For Each( {value, index}, SwitchOption, oder = Insert( oder, Num( Word( 2, value, " " ) ) ) );
oder = Sort List( oder );
For Each( {value, index}, oder,
orderedSwitchOption = Insert( orderedSwitchOption, "Column " || Char( value ) )
);
Graph2 = Graph Builder(
Size( 534, 464 ),
Show Control Panel( 0 ),
Variables( X( :name ), Y( :Column 0 ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);
Graph2 << Column Switcher(
Column( "column 0" ),
orderedSwitchOption,
Title( "Ordered Column" )
);