cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
matth1
Level III

Make Row State Handler stops working if table is sorted

Is it possible to apply a row state handler to a data table and make that handler continue to work if the data table is changed; for example, if a column is sorted by a script or interactively by a user?

 

I currently have two tables of data: one table with summary statistics, one with raw data. The user selects a row in the summary table, the row state handler detects which row is selected, extracts the parameter name and creates a chart from the raw data table using the parameter selected. 

 

It works OK (although it does pick up the row that's been deselected at first before then finding the newly selected row), however it breaks if the user sorts the summary table (e.g. if they want to look at lowest Cpk, or some other metric). 

 

I see the same issue in the following simple example based on the scripting help:

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
f = Function( {a}, Print( a ) );
rs = dt << make row state handler( f );
dt << Select Rows( 1 );
dt << sort( by( :weight ), replace table, order( ascending ) );
dt << Select Rows( 9 );

Output is:

Scriptable[]
[1]

I think this may be related to this wish list item: https://community.jmp.com/t5/JMP-Wish-List/Improve-JMP-s-state-handlers-hover-label-row-state-handle.... Is there any workaround?

 

I am using JMP17.0 on MacOS.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Make Row State Handler stops working if table is sorted

Hello,

 

Perhaps you can use a report to drive the script. Table boxes can run scripts when rows are selected, and don't seem to break when the summary table is sorted--try the below to get an idea.

 

Names Default To Here(1);

dt = open ("$Sample_Data\Car Physical Data.jmp");

dtSum = dt << summary( group(:Country), mean(:weight) );

nw = new window("ex",
	dtb = Data Table Box( dtSum,
	 << Set Selectable rows,
	 << Set Click Sort  )
);

//do something when a row is selected. Here, we just print the country.
dtb << Set Row Change Function ( function( { this }, 
	selCountry = this[1][this << get selected rows];
	print(evalinsert("Selected country is: ^selCountry[1]^."))
) );

Cheers,

Brady

View solution in original post

5 REPLIES 5
matth1
Level III

Re: Make Row State Handler stops working if table is sorted

By the way, I realise that the scripted example I gave could be easily solved by adding 

 

rs = dt << make row state handler( f );

immediately after my Sort() command. It's the interactive case (where a user manually sorts the table by a column then selects a row) that is the issue.

 

 

I tried a workaround by adding a script to the table which resets the row state handler:

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
f = Function( {a}, Print( a ) );
rs = dt << make row state handler( f );
dt << new script("Fix Row State Handler",
	rs = dt << make row state handler( f );
); // errors when the script is run!
dt << Select Rows( 1 );
wait(0);
dt << sort( by( :weight ), replace table, order( ascending ) );
rs = dt << make row state handler( f ); // fixes issue when scripting
dt << Select Rows( 9 );

but I get an error when i click the green triangle to run the script:

 

 

Send Expects Scriptable Object in access or evaluation of 'Send' , dt <<  /*###*/make row state handler( f ) /*###*/ at line 6 in ...

However, even if this worked it would not be ideal since it requires a user to remember to do this after sorting the table.

 

Thanks,

Matthew.

 

Re: Make Row State Handler stops working if table is sorted

Hello,

 

Perhaps you can use a report to drive the script. Table boxes can run scripts when rows are selected, and don't seem to break when the summary table is sorted--try the below to get an idea.

 

Names Default To Here(1);

dt = open ("$Sample_Data\Car Physical Data.jmp");

dtSum = dt << summary( group(:Country), mean(:weight) );

nw = new window("ex",
	dtb = Data Table Box( dtSum,
	 << Set Selectable rows,
	 << Set Click Sort  )
);

//do something when a row is selected. Here, we just print the country.
dtb << Set Row Change Function ( function( { this }, 
	selCountry = this[1][this << get selected rows];
	print(evalinsert("Selected country is: ^selCountry[1]^."))
) );

Cheers,

Brady

matth1
Level III

Re: Make Row State Handler stops working if table is sorted

Hi Brady, this is brilliant, thank you! This has given me a much more robust and usable solution that I had before.

One question: is it possible to query the Data Table Box from JSL to find out which column (if any) the user has sorted the table by?

Regards,

Matthew.

Re: Make Row State Handler stops working if table is sorted

Hello Matthew,

 

I don't know a way to query to see which (if any) column was used to sort the table. You could brute force this by checking the columns, but it may get expensive, depending on table size.

matth1
Level III

Re: Make Row State Handler stops working if table is sorted

Hi Brady,

thanks for the tip. 

 


I don't know a way to query to see which (if any) column was used to sort the table. You could brute force this by checking the columns, but it may get expensive, depending on table size.


Could you help me with the brute forcing method? I've tried looking at the properties of the DataTableColBox and the window itself and not found anything that helps me see if it's sorted.
Thanks,

Matthew.