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
蘇71
Level II

How to Dynamically List Column names of Selected Data Table?

Hello there,

I'm tring to creat a windows like Tables-Join, which the second outline box could dynamically list the column names of selected data table in the upleft corner list box.

Thanks in advanced.

3 ACCEPTED SOLUTIONS

Accepted Solutions

Re: How to Dynamically List Column names of Selected Data Table?

Hello,

 

You can use code like the following to do this. Try running this code when you have a few data tables open.

 

Cheers,

Brady

Names Default To Here( 1 );

//get a list of window names
windows = Window() << get window title;

//remove ones that are not data tables--need to start at back of list, because its length will change as we delete items
For( i = N Items( windows ), i > 0, i--,
	If( (Window( windows[i] ) << Window Class Name) != "DataTable",
		Remove From( windows, i )
	)
);

//make a dialog window
nw = New Window( "Sample",
	vlb1 = V List Box(
		lb1 = List Box(
			windows,	//populate the listbox with data table names
			
			//here is the script that runs each time someone clicks in the top box
			//delete the current column list box, if it exists
			Try( lb2 << delete );				
			
			//append a new col list box, with all columns of the data table selected in the listbox
			vlb1 << append( lb2 = Col List Box( Data Table( (lb1 << get selected)[1] ), all ) );		
		)
	)
);

brady_brady_0-1630705687855.pngbrady_brady_1-1630705698471.png

 

View solution in original post

蘇71
Level II

Re: How to Dynamically List Column names of Selected Data Table?

Thank you for your reply. I replace 'col list box' with 'filter col selector', it doesn't work as expected, a red triangle left every time I select a table, the column list doesn't update accordingly.

how does it work through by using 'filter col selector' ?

Names Default To Here( 1 );

//get a list of window names
windows = Get Data Table List();

/*remove ones that are not data tables--need to start at back of list, because its length will change as we delete items
For( i = N Items( windows ), i > 0, i--,
	If( (Window( windows[i] ) << Window Class Name) != "DataTable",
		Remove From( windows, i )
	)
);
*/
//make a dialog window
nw = New Window( "Sample",
	vlb1 = V List Box(
		lb1 = List Box(
			windows, 	//populate the listbox with data table names
			
			//here is the script that runs each time someone clicks in the top box
			//delete the current column list box, if it exists
			Try( lb2 << delete );				
			
			//append a new col list box, with all columns of the data table selected in the listbox
			vlb1 << append( lb2 = Filter Col Selector( Data Table( (lb1 << get selected)[1] ), all ) );
		)
	)
);

截屏2021-09-04 上午11.40.41.png

View solution in original post

jthi
Super User

Re: How to Dynamically List Column names of Selected Data Table?

Quickly looking at this there are two things that must be taken care of when using Filter Col Selector:

  1. It seems like Filter Col Selector always uses the Current Data table() and you cannot give it direct reference to the datatable you want to use. Based on the Scripting Index it should accept Datatable(name) as argument so most likely a bug (at least in JMP16.1).
  2. The red triangle of Filter Col Box is a different DisplayBox which has to be deleted.

To work around the reference thing you could try changing the Current Data Table() based on the user selection and to delete also the red triangle, you can wrap Filter Col Box around V List Box and delete that.

Names Default To Here(1);

//get a list of window names
windows = Get Data Table List();

/*remove ones that are not data tables--need to start at back of list, because its length will change as we delete items
For( i = N Items( windows ), i > 0, i--,
	If( (Window( windows[i] ) << Window Class Name) != "DataTable",
		Remove From( windows, i )
	)
);
*/
//make a dialog window
nw = New Window("Sample",
	vlb1 = V List Box(
		lb1 = List Box(
			windows, 	//populate the listbox with data table names
			
			//here is the script that runs each time someone clicks in the top box
			//delete the current column list box, if it exists
			Try(vlb2 << delete);				
			
			//append a new v list box which includes filter col selector 
			Current Data Table(Data Table((lb1 << get selected)[1]));
			vlb1 << append(vlb2 = V List Box(Filter Col Selector()));
		)
	)
);

Also here is simple script to replicate the issue with Filter Col Selector:

Names Default To Here(1);
//Open two data tables
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Consumer Preferences.jmp");

//Make sure the one not used in filter col selector is current data table
Current Data Table(dt2);
wait(0);

//Create filter col selector with non current data table
New Window("Filter Col Selector Example",
	fontobj = lb = Filter Col Selector(Data table("Big Class"))
);
-Jarmo

View solution in original post

4 REPLIES 4

Re: How to Dynamically List Column names of Selected Data Table?

Hello,

 

You can use code like the following to do this. Try running this code when you have a few data tables open.

 

Cheers,

Brady

Names Default To Here( 1 );

//get a list of window names
windows = Window() << get window title;

//remove ones that are not data tables--need to start at back of list, because its length will change as we delete items
For( i = N Items( windows ), i > 0, i--,
	If( (Window( windows[i] ) << Window Class Name) != "DataTable",
		Remove From( windows, i )
	)
);

//make a dialog window
nw = New Window( "Sample",
	vlb1 = V List Box(
		lb1 = List Box(
			windows,	//populate the listbox with data table names
			
			//here is the script that runs each time someone clicks in the top box
			//delete the current column list box, if it exists
			Try( lb2 << delete );				
			
			//append a new col list box, with all columns of the data table selected in the listbox
			vlb1 << append( lb2 = Col List Box( Data Table( (lb1 << get selected)[1] ), all ) );		
		)
	)
);

brady_brady_0-1630705687855.pngbrady_brady_1-1630705698471.png

 

蘇71
Level II

Re: How to Dynamically List Column names of Selected Data Table?

Thank you for your reply. I replace 'col list box' with 'filter col selector', it doesn't work as expected, a red triangle left every time I select a table, the column list doesn't update accordingly.

how does it work through by using 'filter col selector' ?

Names Default To Here( 1 );

//get a list of window names
windows = Get Data Table List();

/*remove ones that are not data tables--need to start at back of list, because its length will change as we delete items
For( i = N Items( windows ), i > 0, i--,
	If( (Window( windows[i] ) << Window Class Name) != "DataTable",
		Remove From( windows, i )
	)
);
*/
//make a dialog window
nw = New Window( "Sample",
	vlb1 = V List Box(
		lb1 = List Box(
			windows, 	//populate the listbox with data table names
			
			//here is the script that runs each time someone clicks in the top box
			//delete the current column list box, if it exists
			Try( lb2 << delete );				
			
			//append a new col list box, with all columns of the data table selected in the listbox
			vlb1 << append( lb2 = Filter Col Selector( Data Table( (lb1 << get selected)[1] ), all ) );
		)
	)
);

截屏2021-09-04 上午11.40.41.png

jthi
Super User

Re: How to Dynamically List Column names of Selected Data Table?

Quickly looking at this there are two things that must be taken care of when using Filter Col Selector:

  1. It seems like Filter Col Selector always uses the Current Data table() and you cannot give it direct reference to the datatable you want to use. Based on the Scripting Index it should accept Datatable(name) as argument so most likely a bug (at least in JMP16.1).
  2. The red triangle of Filter Col Box is a different DisplayBox which has to be deleted.

To work around the reference thing you could try changing the Current Data Table() based on the user selection and to delete also the red triangle, you can wrap Filter Col Box around V List Box and delete that.

Names Default To Here(1);

//get a list of window names
windows = Get Data Table List();

/*remove ones that are not data tables--need to start at back of list, because its length will change as we delete items
For( i = N Items( windows ), i > 0, i--,
	If( (Window( windows[i] ) << Window Class Name) != "DataTable",
		Remove From( windows, i )
	)
);
*/
//make a dialog window
nw = New Window("Sample",
	vlb1 = V List Box(
		lb1 = List Box(
			windows, 	//populate the listbox with data table names
			
			//here is the script that runs each time someone clicks in the top box
			//delete the current column list box, if it exists
			Try(vlb2 << delete);				
			
			//append a new v list box which includes filter col selector 
			Current Data Table(Data Table((lb1 << get selected)[1]));
			vlb1 << append(vlb2 = V List Box(Filter Col Selector()));
		)
	)
);

Also here is simple script to replicate the issue with Filter Col Selector:

Names Default To Here(1);
//Open two data tables
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Consumer Preferences.jmp");

//Make sure the one not used in filter col selector is current data table
Current Data Table(dt2);
wait(0);

//Create filter col selector with non current data table
New Window("Filter Col Selector Example",
	fontobj = lb = Filter Col Selector(Data table("Big Class"))
);
-Jarmo
蘇71
Level II

Re: How to Dynamically List Column names of Selected Data Table?

Names Default To Here(1);
//Open two data tables
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Consumer Preferences.jmp");

//Make sure the one not used in filter col selector is current data table
Current Data Table(dt2);
wait(0);

//Create filter col selector with non current data table
New Window("Filter Col Selector Example",
	fontobj = lb = Filter Col Selector(Data table(dt)) //replace "big class" with dt work.
);

Replace data table("big class") with data table (dt),it work.