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

Allow Name Selection In Column be used for multiple selections

From time to time I have come across something interesting in row level of data and I would like to give it a value in column, which would allow me to use it in analysis. I think I could do this with a Formula and using Row States with different colors / markers, but I think expanding the functionality of Name Selection In Column would be even more helpful.

Currently Name Selection In Column opens as Modal and will easily only allow using it once, to use it again you will have to reopen it. My suggestion is to change the functionality/add new functionality which would allow the Name Selection In Column used multiple times. Adding check box similar to some other platforms which have option of Keep Dialog Open would be most likely enough (with the removal of Modal).

 

I have made my own script to help me with this:

jthi_1-1625141063951.png

 

The script is definitely not perfect, but is enough for simple use:

Names Default To Here(1);
/************************************************************************

************************************************************************/

If(
	IsEmpty(Current Data Table()),
	Caption("No current data table");
	stop();
);

wList = Get Window List(Window) << Get Window Title();
If(Contains(wList, "Name Selections in Column"),
	pos = Get Window(Current Data Table()) << Get Window Position;
	size = Get Window(Current Data Table()) << Get Window Size;
	cursize = Window("Name Selections in Column") << Get Window Size;
	Window("Name Selections in Column") << Move Window(pos[1] + (size[1]-curSize[1]) / 2 , pos[2] + (size[2]-curSize[2]) / 2);
	Window("Name Selections in Column") << Bring Window To Front;
	stop();
);

//add indicator to show which datatable is being modified...
//window location,
//new column modal window location...
nw = New Window("Name Selections in Column", <<Show Toolbars(0), <<Show Menu(0),
	Border Box(Left(10), Right(10), Top(0), Bottom(10),
		V List Box(
			Text Box("Label currently selected rows in specified column"), Spacer Box(Size(0,10)),
			H List Box(Align(center),
				Text Box("Column Name", << Set Width(120)), Spacer Box(size(5,0)),
				Window:tbCol = Text Edit Box("Label", << Set Width(100)),
				Window:cbCol = Check Box({"Label"}),
				Button Box("Create Column", 
					<< Set Script(
						Window:tempDt = Current Data Table();
						Window:newColName = Window:tbCol << get text;
						Window:colNames = Window:tempDt << Get Column Names("String");
						If(Contains(Window:colNames, Window:newColName),
							//already exists... want to create new column?
							//
							Window:nw = New Window("Column already exists", << Modal, << Return Result,
								//Create new column with index or use existing?
								V List Box(
									Text Box("Create new column with index or use existing?"),
									Text Box("Press OK to create new with index and Cancel to continue with existing", << set wrap(1000)),
									Spacer Box(Size(0,10)),
									H List Box(Button Box("OK"), Button Box("Cancel"));
								);	
							);
							If(Window:nw["button"] == 1,
								Window:newCol = Window:tempDt << New Column(Window:newColName, Character, Nominal);
								Window:tbCol << Set Text(Window:newCol << Get Name)
								//,Window:newCol = Column(Window:tempDt, Window:newColName);
							),
								Window:newCol = Window:tempDt << New Column(Window:newColName, Character, Nominal);
						);
						//check if column exists
						//If...
						If(Contains(Window:cbCol << get selected, "Label"),
							Window:newCol << Set Labeled;
						)
					);
				)
			),
			H List Box(Align(center),
				Text Box("Value for Selected", << Set Width(120)), Spacer Box(size(5,0)),
				Window:tbRow = Text Edit Box("", << Set Width(100)),
				Window:cbRow = Check Box({"Label"}),
				Button Box("Add values", 
					<<Set Script(
						Window:tempDt = Current Data Table();
						Window:rowsToReplace = Window:tempDt << Get Selected Rows;
						Column(Window:tempDt, Window:tbCol << Get Text)[Window:rowsToReplace] = Window:tbRow << Get Text;
						If(Contains(Window:cbRow << get selected, "Label"),
							Window:tempDt << Label(1),
							Window:tempDt << Label(0)
						);
					);
				);
			),
			H List Box(Align(center),
				Text Box("Value for empty rows", << Set Width(120)), Spacer Box(size(5,0)),
				Window:tbRowEmpty = Text Edit Box("", << Set Width(100)),
				Window:cbRowEmpty = Check Box({"Label"}),
				Button Box("Add values", 
					<<Set Script(
						Window:tempDt = Current Data Table();
						Window:rowsToReplace = Loc(Column(Window:tempDt, Window:tbCol << Get Text) << get as matrix, "");
						Column(Window:tempDt, Window:tbCol << Get Text)[Window:rowsToReplace] = Window:tbRowEmpty << Get Text;
						If(Contains(Window:cbRowEmpty << get selected, "Label"),
							Window:tempDt << Label(1),
							Window:tempDt << Label(0)
						);
					);
				);
			),
			Window:cb = Check Box({"Label Column", "Label Non-empty rows"}),
			H List Box(
				Spacer Box(Size(250,0)),
				Button Box("OK", 
					Window:tempDt = Current Data Table();
					If(Contains(Window:cb << Get Selected, "Label Column"),
						Column(Window:tempDt, Window:tbCol << Get Text) << Set Labeled;
						
					);
					If(Contains(Window:cb << Get Selected, "Label All non-empty rows"),
						//label non empty rows
						Window:tempRows = Loc Nonmissing(Column(Window:tempDt, Window:tbCol << Get Text) << get as matrix);
						Window:tempDt << Select Rows(Window:tempRows);
						Window:tempDt << Label(1);
						Window:tempDt << Clear Select;
					);
					Window("Name Selections in Column") << Close Window();
				),
				Button Box("Close", Window("Name Selections in Column") << Close Window());
			);
		)
	)
);

//Initial move window
pos = Get Window(Current Data Table()) << Get Window Position;
size = Get Window(Current Data Table()) << Get Window Size;
cursize = Window("Name Selections in Column") << Get Window Size;
Window("Name Selections in Column") << Move Window(pos[1] + (size[1]-curSize[1]) / 2 , pos[2] + (size[2]-curSize[2]) / 2);

I have built an Add-in of the script which is attached (works only in Windows). It has an shortcut Ctrl+Shift+Space. The idea behind the shortcut is that if the window goes missing, you can use the shortcut to bring it to front and continue adding values.

jthi_0-1625140976367.png

If people feel like the Add-in is helpful, I can submit it for a review to File-Exchange/Add-ins.

3 Comments
asj
Level II

This Add-in is very helpful!

hogi
Level XII

seems that most Jmp users suffer from similar limitations
interesting, this wish still has status "new" - since 2021 ?!?!


I just noticed that I submitted a similar one:
Name Selection in Column: could be my favorite tool :) if ... 

hogi
Level XII

you may try QuickSelect Toolbar 

hogi_0-1714993117178.png

 

it's kind of complimentary:
- no option to specify the column name

- no possibility to specify a value for non-selected rows

 

but:
- Tags: drop down list (with the possibility to specify user defined values)

- multiple response, to specify >=1 tags for a single row

hogi_1-1714993260338.png