Choose Language Hide Translation Bar
Highlighted
FN
FN
Level V

Calling 'Move Selected Columns' from a 'Filter Col Selector' in a GUI.

I am trying to call the the Menu Move Selected Columns from a GUI.

 

While this code calls it, it does not reorganize the table (probably due to the wrong usage of MoveSelectedColumns...)

 

MoveButtonPress=Function({this},
        // colListData is a Filter Col Selector in a GUI
	selectedElements = colListData << GetSelected;
	DataTable1 << move selected columns(selectedElements, after()); // TODO fix this
	colListData << Reset; //refresh selector
	colListData << NameContains (" "); // reactivates filter
);

 

3 REPLIES 3
Highlighted

Re: Calling 'Move Selected Columns' from a 'Filter Col Selector' in a GUI.

I changed the code a bit to use "GetSelectedColumns" rather than "Get Selected."  Please let me know if this works for you?

DataTable1=Open("$SAMPLE_DATA/Big Class.jmp");

nw=New Window("Move Selected Columns button",
	Button Box("Move Selected Columns",
	
	selectedElements = DataTable1 << GetSelectedColumns;
	DataTable1 << move selected columns(selectedElements, after(:name));
		
	)
);
Highlighted
FN
FN
Level V

Re: Calling 'Move Selected Columns' from a 'Filter Col Selector' in a GUI.

I get an error when using your code:

'Unrecognized key word'.

On the other hand, 'after(:name)' will not work in other data set, as we are using the name of the column as indication on where to put it.

I see two options:
- Get the first column name and move it up/down by one position.
- Or open the menu of move columns and select To First, To Last, after: list of tags.


Highlighted

Re: Calling 'Move Selected Columns' from a 'Filter Col Selector' in a GUI.

I believe you are getting the "unrecognized key word" error because the "Move Selected Columns" feature requires a column reference as input, and not a column name.  Please take a look at the code below.  I added some functionality, including the ability where to choose an "after" column.  Is this more helpful?

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );



nw = New Window( "Move Selected Columns button", 

	H List Box(
		V List Box(
			Text Box( "Select Columns to Move" ),
			columns_to_move = Col List Box( Data Table( dt ), all )
		),
		V List Box(
			Text Box( "Before Before or After Selected Column" ),
			after_column_list = Col List Box( Data Table( dt ), all )
		)
	),
	H List Box(
		Button Box( "Move To First", 
	
			MoveColumns = columns_to_move << GetSelected;//Get List Of Column Names
			dt << Select Columns( MoveColumns );//Select Columns
	
			colList = {};//List to hold Column References
			For( i = 1, i <= N Items( MoveColumns ), i++, 
	
				colList[i] = Column( dt, MoveColumns[i] )//For-loop used to convert list of Column Names to Column References
			);
			dt << move selected columns( colList, To First );//Move Columns to First
		
		),
		Button Box( "Move To Last", 
	
			MoveColumns = columns_to_move << GetSelected;//Get List Of Column Names
			dt << Select Columns( MoveColumns );//Select Columns
	
			colList = {};//List to hold Column References
			For( i = 1, i <= N Items( MoveColumns ), i++, 
	
				colList[i] = Column( dt, MoveColumns[i] )
			);
			dt << move selected columns( colList, To Last );//Move Columns to First
		),
		Button Box( "Move After Column", 
	
			MoveColumns = columns_to_move << GetSelected;//Get List Of Column Names
			dt << Select Columns( MoveColumns );//Select Columns
	
			aftercol_string = after_column_list << GetSelected;//Get Column to move after
			aftercol_ref = Column( dt, aftercol_string[1] );//Column reference - only first item in case someone chose more than one
	
			colList = {};//List to hold Column References
			For( i = 1, i <= N Items( MoveColumns ), i++, 
	
				colList[i] = Column( dt, MoveColumns[i] )
			);
			dt << move selected columns( colList, after( aftercol_ref ) );
		
		)
	)
	
);
Article Labels

    There are no labels assigned to this post.