cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Column reorder > Sort by Name / Data Type / Role > SELECTED COLUMNS ONLY

Hi JMP Team,

 

Would it be possible to enhance the Column Reorder command by allowing sorting of only subset of selected columns?

 

Thanks,

 

TS

10 Comments
pcarroll1
Level IV

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.

jthi
Super User

@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:

jthi_0-1642002499157.png

After:

jthi_1-1642002516269.png

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.

pcarroll1
Level IV

@jthi, Thanks for the code!  I will use it.  

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.

jthi
Super User

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:

Starting situation:

jthi_0-1642010066884.png

Sorting by name only inside selected columns:

jthi_1-1642010118280.png

Sort while grouping them together:

jthi_2-1642010151655.png

 

 

Thierry_S
Super User

@jthi,

 

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.

Best,

TS 

jthi
Super User

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:

jthi_0-1642054105008.png

 

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.

jthi
Super User

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:

jthi_0-1642157217228.png

 

Settings window:

jthi_1-1642157406617.png

 

Possible things which could be added:

  1. More sorting options (all the same as JMP already offers)
  2. Add Toolbar
  3. Move to Cols menu
  4. Refactor code, because it got messy after implementing options
  5. Better management for previous column orders
    1. Combine with Save Current Column Order and Grouping ?

 

jthi
Super User

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.

 

pcarroll1
Level IV

Sorry,  I didn't realize that this conversation continued and I only got back on the community site today.  

I agree with what was done.

Thanks,

Pat

 

jthi
Super User

Add-in has now been published and should be available here Add-In - Order Selected Columns .