cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
lukasz
Level IV

How to update table after sorting?

Hello Everybody,

I have an issue regarding sorting of a table. I wanted to sort table by Date (located in Date1 column) and I am doing that after certain condition is met. However, it does not sort and replace the table EL_summary after sorting. Is there any refreshing necessary? I put also some delay, I thought one need to wait some time. When I am not using replace table(1), the new Table under different name is created and opened (what I don't want) and again data in this table is not sorted. After that, however, data in EL_summary seems to be updated and sorted. I would appreciate for pointing what I am missing. Best regards


Current Data Table( EL_summary );

if( N rows(EL_summary) > 0, EL_summary << sort(by(:name("Date1")), Order( Ascending ), replace table(1)));
wait(1);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
lukasz
Level IV

Re: How to update table after sorting?

Ok, I manage to hide the new data table. That data table was the current data table so I disabled its visibility by using

Current Data Table() << ShowWindow( 0 );

Thank you all for support. Best regards.

View solution in original post

12 REPLIES 12
txnelson
Super User

Re: How to update table after sorting?

is your data table inked to a previous table, so it can not be changed?
Jim
karenb
Level II

Re: How to update table after sorting?

Hi,

This code performed as expected when there are no graphs open:

  Untitled = data table("Untitled.jmp");
  if( N rows(Untitled) > 0, Untitled << sort(by(:name("Column 1")), Order( Ascending ), replace table(1)));

But the sort fails to work if you have any graphs open,
  

 Untitled <<Distribution( Continuous Distribution(Column( :Column 1 )));
   if( N rows(Untitled) > 0, Untitled << sort(by(:name("Column 1")), Order( Descending ), replace table(1)));

Look at the log file and we see:
  

JMP cannot replace the existing table because there are report windows that depend on the previous ordering.

But if we remove replace table, it will execute without error but it will launch a new datatable with the sorted rows which is not desired.
 

  Untitled <<Distribution( Continuous Distribution(Column( :Column 1 )));
   if( N rows(Untitled) > 0, Untitled << sort(by(:name("Column 1")), Order( Descending )));

So you can check the log file to see if it is informative. If you have any dependent graphs or tables open, maybe you need to rethink the logic of the script. Is it possible to re-sort before making dependent tables and graphs, for example.

 

 

 

 

lukasz
Level IV

Re: How to update table after sorting?

Hello, thank you for suggestions!

I created one GUI and sorting needs to be done after I select one item from the List Box. After that certain pictures needs to be displayed in this GUI in the order based on the sorted values. Actually, JMP is not providing any useful log information indicating source of problem. Is there any way to hide or make invisible the new (and undesired) datatable that is created after sorting? That would be some workaround.

txnelson
Super User

Re: How to update table after sorting?

You can handle this in a couple of different ways.

The output that is keeping the data table from sorting, can be moved to a Journal for display, and the original display can be then deleted, which will allow the sorting to then take place.

Yo can also create a new data table that is either invisible, or private, which will keep the new data table from being displayed.  Look for the Invisible, or Private options in subsetting the data table in the Scripting Index.

Jim
lukasz
Level IV

Re: How to update table after sorting?

Ok, I manage to hide the new data table. That data table was the current data table so I disabled its visibility by using

Current Data Table() << ShowWindow( 0 );

Thank you all for support. Best regards.

hogi
Level XII

Re: How to update table after sorting?

Hi, what is the official way to sort a data table via JSL with the option ReplaceTable()?

 

As discussed before, If there are open Reports, the script crashes with the error message:

hogi_0-1689588481706.png

... even if the graph doesn't depend of the ordering in the data table:

 

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
	Size( 437, 413 ),
	Graph Spacing( 4 ),
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);

dt<< Sort(	By( :height ),	Replace Table,	Order( Ascending ));

 

How about replacing the text with something like:

 

Unfortunately, in the current version of Jmp, there is no chance to sort a table with open reports.

Jmp cannot replace the existing table because there is some chance ... hm, you know, report windows might depend on the previous ordering. Unfortunately, there is no option to check that - and there is no option to ignore it. So the Script will stop here. 

 

jthi
Super User

Re: How to update table after sorting?

Use Try to catch the error and then handle the error accordingly.

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(437, 413),
	Graph Spacing(4),
	Variables(X(:height), Y(:weight), Overlay(:sex)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2)))
);

Try(
	dt << Sort(By(:height), Replace Table, Order(Ascending));
,
	If(Starts With(exception_msg[1], "JMP cannot replace the existing table because there are report windows"),
		dt1 = dt << Sort(By(:age), Order(Ascending)); // will create new table
		/*
		// if you wish to just keep one, order to create new, close old and rename new
		old_name = dt << get name;
		Close(dt, no save)
		dt1 << set name(old_name);
		dt = dt1;
		*/
	);
);

Using JMP > Reshape Your Data > Sort Data Tables 

Replace Table

Replaces the original data table with the sorted table instead of creating a new table with the sorted values. This option is not available if there are any open report windows generated from the original table.

-Jarmo
hogi
Level XII

Re: How to update table after sorting?

Hm, with this workaround the script won't crash ...

on the other hand: the data won't be sorted but a new table will be generated

 

At the moment, I will prefer something like:

Try (sort,
Caption("Sorry, not possible to sorting the table, please close all reports and sort manually");stop());

 

For the future, I hope there will be something like
Data Table : get reports (and other options) 

 

Try(
	sort, 
	If( New Window( "ask User", ... ), 
		myAffectedReports = dt << get reports with ordering issues();
		myAffectedReports << close window;
		sort;
	)
)

or

 

sort(..., ignoreEffectOnReports())

or

sort(..., closeReportsWithOrderingIssue());

 

hogi
Level XII

Re: How to update table after sorting?

I want to write an Addin which sorts the data table.

 

Instead of Try(sort, error message) somewhere within the execution of the AddIn, I want to inform the user in the beginning that he has to close all reports before starting the Addin.

 

How can I do this with Jmp17?