Scripting Table Sort by User Defined ColumnWarning - scripting newbie @ work. I'm working on a script, a part of which sorts the data table by the user selected column (obtained by ColList selection and Eval List).
This does not work, it brings up the Sort dialog, which I don't want:
dt << Sort( By(_userCol), Order(Ascending), Replace Table);
When I hover over _userCol, the assigned column is shown in the scripting window. If I use the exact column name, it works without bringing up the Sort dialog:
dt << Sort( By(:Timestamp), Order(Ascending), Replace Table);
How can I script this using the variable _userCol?
Thanks!
Re: Scripting Table Sort by User Defined ColumnJust got it on another thread.
1. first add list check
Column( Data Table( "Summary" ),"ITEM") << Set Property(List Check, summary_items);
2. Perform table sort.
https://community.jmp.com/t5/Discussions/Custom-Sort-Order/td-p/3119
Re: Scripting Table Sort by User Defined ColumnWell....kind of.
If you set the "Value Ordering" column property for the column you want oredered, and then sort by that column, the resulting sort will be ordered based upong the specified order.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt:name << set property(
"value ordering",
{"ALICE", "BARBARA", "CHRIS", "ALFRED", "CLAY", "DAVID", "EDWARD", "CAROL", "AMY", "ELIZABETH", "DANNY",
"HENRY", "JACLYN", "JAMES", "JANE", "JEFFREY", "JOE", "JOHN", "KIRK", "LAWRENCE", "JUDY", "FREDERICK",
"LEWIS", "KATIE", "LESLIE", "LINDA", "MARION", "MARK", "LILLIE", "LOUISE", "MARY", "MICHAEL", "PATTY",
"WILLIAM", "SUSAN", "PHILLIP", "MARTHA", "ROBERT", "TIM"}
);
dt << sort( by( :name ), order( ascending ), replace table( 1 ) );Re: Scripting Table Sort by User Defined ColumnHello Sir,
Is it possible if i can order the the table by a predefined list instead of ascending or descending order. e.g
dt = open("$sample_data\Big Class.jmp");
_userCol = "name";
dt << Sort( By(column(dt, _userCol)), Order(Descending), Replace Table);<BR /><BR />instead of the above, i like to order the table by name in a order given by "list" below?
list={"BARBARA","ALFRED","CHRIS","ALICE","AMY","CAROL","CLAY","DANNY","DAVID","EDWARD","ELIZABETH","FREDERICK","HENRY","JACLYN","JAMES","JANE","JEFFREY","JOE","JOHN","JUDY","KATIE","KIRK","LAWRENCE","LESLIE","LEWIS","LILLIE","LINDA","LOUISE","MARION","MARK","MARTHA","MARY","MICHAEL","PATTY","PHILLIP","ROBERT","SUSAN","TIM","WILLIAM"};Re: Scripting Table Sort by User Defined Column<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Thanks. Solved my problem. Subsequently learned about using As Column(_usercol) when using the column in a formula.
Re: Scripting Table Sort by User Defined ColumnYou need to use the column function or the eval function:
dt = open("$sample_data\Big Class.jmp");
_userCol = "age";
dt << Sort( By(column(dt, _userCol)), Order(Ascending), Replace Table);
OR
dt << Sort( By(eval(_userCol)), Order(Ascending), Replace Table);