I've wanted to do this for some time. It would be helpful to re-order columns alphabetically within a Group. Sometimes I add new columns to a Column Group but then finding them becomes a problem because the names are no longer ordered unless I do it manually.
@pcarroll1if you want to always alphabetically order the columns in groups, you should be able to script it.
This script requires JMP16, due to using For Each. It should order columns in all of the groups in the datatable alphabetically inside the group (if you want to reorder only specific group, you could add selection for groups which you want to re-order)
Names Default To Here(1);
//Alphabetically order columns in groups JMP16
dt = Current Data Table();
col_groups = dt << Get Column Groups Names("String");
col_list = dt << Get Column Names("String");
For Each({col_group}, col_groups,
cols_in_group = dt << get column group(col_group);
//get index of first column in group
index_of_first = Contains(col_list, cols_in_group[1] << get name);
ordered_cols_in_group = Sort List(cols_in_group);
//fix indices
ordered_cols_in_group = ordered_cols_in_group;
dt << Move Selected Columns(ordered_cols_in_group, After(Column(dt, index_of_first)));
);
Before:
After:
Script for example table:
New Table("Untitled 3",
Add Rows(0),
New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("x", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("a 2", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("c", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("b 2", Numeric, "Continuous", Format("Best", 12), Set Values([]), Set Display Width(82)),
New Column("z", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("a 3", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("x 2", Numeric, "Continuous", Format("Best", 12), Set Values([])),
Group Columns(:x, 4),
Group Columns(:z, 3)
)
It should be fairly easy to create an addin which should be able to do what was asked in this wish list item, thou of course it would be better that it would be included in JMP.
I think we both agree this should be a basic feature in JMP. "Cols -> Reorder Cols -> Reorder By Name" could work similar to other features such as Select Duplicate Rows, where, if no columns are select JMP finds duplicate rows where all columns are the same. But if columns are selected, JMP finds duplicate rows over those columns only.
I agree on that, that if no columns are selected -> current functionality else use selected columns.
How do you think the column ordering should be done on the selected columns? Should the sorting only be done by using the selected columns, or should all the columns be moved together besides the first selected column (I have already written the code but I'll have to test it). Couple of images to explain what I'm asking:
Thank you so much for applying your exceptional skills to this question.
Regarding the behavior of column reordering for selected columns, I suggest that the default would be to reorder AND regroup the sorted columns and that there would be an option to leave the reordered columns in place.
Ok, I'll try to figure out how to add some simple "settings" menu for that addin, because I think it is a bit unnecessary to open a menu when the script(s) is(are) launched.
Menu like this could be built, but I'm not sure if it is necessary:
It does already support those options, but user would have to make modifications which are in settings.json file inside the addin, that's why it needs some small UI to make the changes.
The addin should now be ready. I'll try to get post created to JMP Community's Discussion area today or during weekend with the addin after I have done some more testing.
After installation new submenu will be added to Add-Ins menu (it could be added to Cols menu, but even getting this to work as an addin was enough work and hassle for now).
Add-ins menu:
Settings window:
Possible things which could be added:
More sorting options (all the same as JMP already offers)
Add Toolbar
Move to Cols menu
Refactor code, because it got messy after implementing options
Add-In has been posted to Community's File Exchange/Add-Ins and is in Awaiting Review state (since 15-Jan-2022).
You should also be able to get the Add-In from here GitHub - Order Selected Columns by downloading the JMP-Tools Order Selected Columns.jmpaddin file and installing it.