cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
tLerman
Level I

How to sort the data table within an application?

I've written a fairly complex JSL application using the JMP Application Builder. The application launcher prompts the user for column selections and then I sort the data by the chosen columns before continuing with processing and visualizations.

 

If the data set has dependent open windows, I need to give the user the option to continue without sorting (the data was likely pre-sorted) or exit the script to let the user deal with the dependent windows.  To this end, I've created the following function:

 

sortThisData = Function ({dt},
	try( dt << Sort (By( Column(snCol), Column(dtCol)), Replace Table) ,
	/* IF thrown */
	if (contains(exception_msg[1], "JMP cannot replace the existing table"),
			ex = New Window( "Alert", <<Modal, <<Return Result,			
				V List Box( H List Box( "Set this value", 
					fontobj = text = Text Box( "JMP cannot replace the existing data table because open report windows depend on the previous ordering." )),
					Text Box(""),
						//H List Box( Button Box( "Continue Without Sorting" ), Button Box( "Cancel Script" ), Button Box("Create New Sorted Data Table") ) )
						
						V List Box (rb = Radio Box( {"Continue Without Sorting", 
										"Cancel Script", 
										"Create New Sorted Data Table"} ) );
					)
			);
		if (ex["rb"] == 1, /*Continue without sorting*/,
			ex["rb"] == 2, /*Stop script*/ (thisModuleInstance << Get Box) << Close Window; stop(),
			ex["rb"] == 3, /* New data table */ dt =  Sort (By(Column(snCol), Column(dtCol)), invisible) 
			)
		)
	);
	return (dt);
);

 

 

 

However, it seems that the application itself counts as a dependent open window! I can't sort the data even if no other windows are open.

 

How can I circumvent this issue and sort my data? I have moved the timing of calling my SORT function, but it needs to happen after the OK button on the launcher was pressed and before the processing/visualizations are done.

 

Any suggestions?

 

 

3 REPLIES 3

Re: How to sort the data table within an application?

I'm not sure I understand your question correctly, it seems that your script does not contain some character (")" in line 2 and "<<").  

sortThisData = Function( {dt},
	Try( newdt = dt << Sort( By( Column( snCol ), Column( dtCol ) ), Replace Table ),  );
	/* IF thrown */
	if(contains(exception_msg[1], "JMP cannot replace the existing table"),
		ex = New Window( "Alert",
			<<Modal,
			<<Return Result,
			V List Box(
				H List Box(
					"Set this value",
					fontobj = text = Text Box(
						"JMP cannot replace the existing data table because open report windows depend on the previous ordering."
					)
				),
				Text Box( "" ), 
				V List Box(
					rb = Radio Box(
						{"Continue Without Sorting", "Cancel Script",
						"Create New Sorted Data Table"}
					)
				)
			)
		);
		If(
			ex["rb"] == 1, /*Continue without sorting*/,
			ex["rb"] == 2, /*Stop script*/ (thisModuleInstance << Get Box) << Close Window;	Throw();,
			ex["rb"] == 3, /* New data table */ newdt = dt << Sort( By( Column( snCol ), Column( dtCol ) ), invisible )
		);
	);
	If(ex["rb"]==3, Return( newdt ), Return( dt ););	
);
tLerman
Level I

Re: How to sort the data table within an application?

Hi,

 

Not sure what you mean by missing characters. But in any case, the issue is the same even if the call to the function above is replaced with a simple Sort Table: 

 

DataTable1 << Sort (By( Column(snCol), Column(dtCol)), Replace Table);

I get the following alert, even though the only open window for DataTable1 is the application that called the Sort function.

 

tLerman_0-1680423779447.png

 

 

 

Re: How to sort the data table within an application?

I'm sorry that I have misunderstood what you want to do. It seems that it is not easy to sort a data table in Application Builder.
It is not a smart solution, you can copy a data table first and then sort the data table. It creates another data table, you should close a table when it is not used.

original_dt = Current Data Table();
dt =  original_dt << Subset( All rows, Selected columns only( 0 ), Link to original data table( 0 ), invisible );
dt << Sort( By( Column( dt, snCol ), Column( dt, dtCol ) ), Replace Table )