How to Sort Open Tables by Table Name<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />I am opening multiple tables at once. Once opened, I loop through all open tables from 1 to N Table() and store the references to each table on a list. However as I loop through each open table, I am not sure how it is arranged in the memory. Bottom line, I want the entries on my list to be sorted according to the table name. Is there a way for me to sort the open tables before storing them to a list? Or to put it in a different angle, what's the best way to sort the table references inside my list (if assuming they are stored on my list at a random order)?
Re: How to Sort Open Tables by Table NameDon't sort the tables after they are open!
Sort the table names before you open them. You can get the table names as a list and then work with them there. Once the list is sorted, open them sequentially and process them.
In this script: https://community.jmp.com/t5/JMP-Scripts/Combine-multiple-txt-or-csv-files/ta-p/24083
I get a list of all of one file type in a directory, and then sequentially open the files. This works great when the individual files are big, or when there are thousands of files.
Re: How to Sort Open Tables by Table NameYou would use the value ordering property of a column to do this. Here's an example:
sort_order_list = {"XXX", "AAA", "DDD", "GGG", "YYY", "QQQ"};
dt = New Table( "Untitled 15", Add Rows( 6 ),
New Column( "To Be Sorted", Character, "Nominal",
Set Values( {"AAA", "DDD", "GGG", "QQQ", "XXX", "YYY"} )
)
);
column(dt, "To Be Sorted") << set property("Value Ordering", sort_order_list);
Now when you sort the column To Be Sorted it will be sorted by the order of the items in the list.
Re: How to Sort Open Tables by Table NameI'm not sure I understand what you are asking, unfortunately.
Suppose I have lst of character string values, myList = {"alpha", "gamma", "beta"} and a table, "My Table", with a column called "Vals" that has one of these three values in each cell.
Do you want to sort 'My Table" so all the rows with "alpha" come first, all the rows with "beta" come last, and all the rows with "gamma" come in between?
Re: How to Sort Open Tables by Table NameHow can i sort the table by values in a list instead of ascending or descending?
lets assume i have unique column values in a list. and the order of values in the list is niether ascending nor descending. how i can use this list to sort the table?
Thanks in advance.
Ram
Re: How to Sort Open Tables by Table NameThanks. I should have thought of this before. I had tried sorting the list before but containing only the table names.
Re: How to Sort Open Tables by Table NameHere's an alternative if a list of Data Table references, rather than strings, is needed:
openTables = {};
For(i = 1, i <= N Table(), i++,
Insert Into(openTables, Data Table(i))
);
Sort List Into(openTables);
// Refer directly to table, e.g.
openTables[1] << Bring Window to Front;
Re: How to Sort Open Tables by Table NameSorry, I overlooked the rather nifty 'Sort List Into()''. Clearly I need to reacquaint myself with 'Help > Scripting Index'.
So, yes, you can do:
// Build the sorted list
openTables = {};
for(t=1, t<=NTable(), t++, InsertInto(openTables, DataTable(t) << getName));
SortListInto(openTables);
// Manipulate (Close) each table in this list
for(t=1, t<=NItems(openTables), t++, Close(DataTable(openTables[t]), NoSave); Wait(1));
Re: How to Sort Open Tables by Table Name@Ian, after the table names are sorted and stored on the openTables list, how can I reference the table? For example, is it possible to do this:
For(a=1, a <= N Table(), a++,
tmpDT = Data Table( openTables );
// ....
);
Separately, would this do the same thing to sort the contents of the list?
Sort List Into( openTables );
regards,
Chris
csoon1 wrote:I am opening multiple tables at once. Once opened, I loop through all open tables from 1 to N Table() and store the references to each table on a list. However as I loop through each open table, I am not sure how it is arranged in the memory. Bottom line, I want the entries on my list to be sorted according to the table name. Is there a way for me to sort the open tables before storing them to a list? Or to put it in a different angle, what's the best way to sort the table references inside my list (if assuming they are stored on my list at a random order)?
Re: How to Sort Open Tables by Table NameHere's one way:
openTables = {};
for(t=1, t<=NTable(), t++, InsertInto(openTables, DataTable(t) << getName));
dt = NewTable("Invisible", NewColumn("Table Name", Character, Values(openTables)), Invisible);
dt << Sort(By("Table Name"), Ascending, ReplaceTable);
openTables = Column(dt, "Table Name") << getValues;
Close(dt, NoSave);