BookmarkSubscribeRSS Feed
markschahl

Community Trekker

Joined:

Jun 18, 2012

Scripting Table Sort by User Defined Column

Warning - 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!

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz

Super User

Joined:

Jun 23, 2011

Solution

Re: Scripting Table Sort by User Defined Column

You 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);

 

2 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Solution

Re: Scripting Table Sort by User Defined Column

You 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);

 

markschahl

Community Trekker

Joined:

Jun 18, 2012

Re: Scripting Table Sort by User Defined Column

Thanks. Solved my problem. Subsequently learned about using As Column(_usercol) when using the column in a formula.