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

UI to select data table

Hi @txnelson ,

 

I have a jsl code which creates a new window , displays all the data table and saves the column names containing particular string in the list . It doesn't work when the current data table tab has different file (see screen shot below).

Jacksmith12_0-1656695027395.png

The script works well when the data table file is selected in the current data table tab but doesn't work when I select the file from the list box and hit ok. Looking for some suggestion

 

// sample data file on Big class
dtNames = {};
For( t = 1, t <= N Table(), t++,
	Insert Into( dtNames, Data Table( t ) << getName )
);
nw2 = New Window( "Data table selector",
			<<modal(),
			Spacer Box( Size( 20, 20 ) ),
			
				
					H List Box(
						Panel Box( "Pick a data table",
							dlg_dtlb_test = List Box( dtNames, width( 280 ), nlines( 10 ), MaxItems( 1 ) ),
							Spacer Box( Size( 10, 10 ) ),
							button = Button Box( "Click here to select the table",
								dt_test_select = dlg_dtlb_test << getSelected;
								
								dt2 = Data Table( dt_test_select[1] );
								colist = {};
								Col_List = dt2 << Get Column Names( "String" );
								
								For( q = 1, q <= N Items( Col_List ), q++, 
				
									If(
										Contains( Col_List[q], "height" ) | Contains( Col_List[q], "weight" ),
										Column( Col_List[q] ) << Set Selected( 1 );
										Insert Into( colist, Col_List[q] );
									)
								);
								sel = button << set button name( "File selected" );
								Caption( "File selected", spoken( 0 ) );
								Wait( 0.2 );
								Caption( remove );
								Wait( 0 );
								Wait( 1 );
								button << set button name( "Click here to select the table" );,
								<<setIcon( "StructuralEquationModelsGoStatus" )
							))));

Thanks,

Jay

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: UI to select data table

You need to change the active data table to the table the user selects.  The easiest way to do this is to add a Current Daa Table() function after the table is selected, and before an action is taken on the data table.  See below for the position I suggest

// sample data file on Big class
dtNames = {};
For( t = 1, t <= N Table(), t++,
	Insert Into( dtNames, Data Table( t ) << getName )
);
nw2 = New Window( "Data table selector",
	<<modal(),
	Spacer Box( Size( 20, 20 ) ), 
			
				
	H List Box(
		Panel Box( "Pick a data table",
			dlg_dtlb_test = List Box( dtNames, width( 280 ), nlines( 10 ), MaxItems( 1 ) ),
			Spacer Box( Size( 10, 10 ) ),
			button = Button Box( "Click here to select the table",
				dt_test_select = dlg_dtlb_test << getSelected;
								
				dt2 = Data Table( dt_test_select[1] );
				current data table(dt2);
				colist = {};
				Col_List = dt2 << Get Column Names( "String" );
								
				For( q = 1, q <= N Items( Col_List ), q++, 
				
					If( Contains( Col_List[q], "height" ) | Contains( Col_List[q], "weight" ),
						Column( Col_List[q] ) << Set Selected( 1 );
						Insert Into( colist, Col_List[q] );
					)
				);
				sel = button << set button name( "File selected" );
				Caption( "File selected", spoken( 0 ) );
				Wait( 0.2 );
				Caption( remove );
				Wait( 0 );
				Wait( 1 );
				button << set button name( "Click here to select the table" );,
				<<setIcon( "StructuralEquationModelsGoStatus" )
			)
		)
	)
);
Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: UI to select data table

You need to change the active data table to the table the user selects.  The easiest way to do this is to add a Current Daa Table() function after the table is selected, and before an action is taken on the data table.  See below for the position I suggest

// sample data file on Big class
dtNames = {};
For( t = 1, t <= N Table(), t++,
	Insert Into( dtNames, Data Table( t ) << getName )
);
nw2 = New Window( "Data table selector",
	<<modal(),
	Spacer Box( Size( 20, 20 ) ), 
			
				
	H List Box(
		Panel Box( "Pick a data table",
			dlg_dtlb_test = List Box( dtNames, width( 280 ), nlines( 10 ), MaxItems( 1 ) ),
			Spacer Box( Size( 10, 10 ) ),
			button = Button Box( "Click here to select the table",
				dt_test_select = dlg_dtlb_test << getSelected;
								
				dt2 = Data Table( dt_test_select[1] );
				current data table(dt2);
				colist = {};
				Col_List = dt2 << Get Column Names( "String" );
								
				For( q = 1, q <= N Items( Col_List ), q++, 
				
					If( Contains( Col_List[q], "height" ) | Contains( Col_List[q], "weight" ),
						Column( Col_List[q] ) << Set Selected( 1 );
						Insert Into( colist, Col_List[q] );
					)
				);
				sel = button << set button name( "File selected" );
				Caption( "File selected", spoken( 0 ) );
				Wait( 0.2 );
				Caption( remove );
				Wait( 0 );
				Wait( 1 );
				button << set button name( "Click here to select the table" );,
				<<setIcon( "StructuralEquationModelsGoStatus" )
			)
		)
	)
);
Jim