我正在嘗試從GUI調用“菜單移動所選列”。
雖然此代碼調用了它,但它不會重新組織表(可能是由於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
);
我對代碼進行了一些更改,以使用“ GetSelectedColumns”而不是“ Get Selected”。請讓我知道這是否適合您嗎?
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));
)
);我相信您會收到“無法識別的關鍵字”錯誤,因為“移動選定的列”功能需要將列引用作為輸入,而不是列名。 請看下面的代碼。 我添加了一些功能,包括在何處選擇“之後”列的功能。 這有幫助嗎?
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 ) );
)
)
);