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

Make row state handler

Hi,

 

I have a JSL code to append button boxes for row selection. The problem is that it keeps appending duplicate boxes even if only 1 row is selected. I only want to append 'n' box for 'n' selected rows. If no rows are selected then it should delete all the boxes in the table box

 

It added 10 boxes just by selecting 1 row. 

Jackie__0-1716125220933.png

 

Names Default To Here( 1 );

dt2 = Open( "$SAMPLE_DATA/Iris.jmp", invisible );


New Window( "",
	H List Box(
		Graph Builder(
			Size( 653, 571 ),
			Show Control Panel( 0 ),
			Variables( X( :Sepal length ), Y( :Sepal width ), Overlay( :Species ) ),
			Elements( Points( X, Y, Legend( 6 ) ) ),
			SendToReport(
				Dispatch( {}, "Sepal length", ScaleBox, {Min( 4.02451368343195 ), Max( 8.24903846153846 ), Inc( 1 ), Minor Ticks( 0 )} ),
				Dispatch( {}, "Sepal width", ScaleBox, {Min( 1.75 ), Max( 5.00400457665904 ), Inc( 1 ), Minor Ticks( 0 )} )
			)
		),
		Spacer Box( size( 10, 0 ) ), 

		Outline Box( "Petal Species",
			Spacer Box( size( 0, 10 ) ),
			Scroll Box(
				size( 350, 150 ),
				disoi = Table Box(
					colbox = Col Box( "Species" ), 
					//imvinum = Number Col Edit Box( "iMINum", {} ),
				
				)
			),
			disoi << set selectable rows( 0 ), 
		
			
	
				
		)
	)
);

f = Function( {this},
	dt2 << begin data update;
	
	list = {};
	
	checnro = N Items( dt2 << getselectedrows );
	
	For( i = 1, i <= checnro, i++,
		Insert Into( list, dt2:Species[dt2 << getselectedrows][i] );
		
		
	);

	For Each( {wascc, idx}, list, 
	//For( k = 1, k <= N Items( list ), k++, 
		
		colbox << append(
		
			Eval(
				Parse(
					"ex" || Char( idx ) ||
					" = Button Box( wascc
					, 
			
				
				New Window( \!"Wikipedia\!",
					<<Type( \!"Dialog\!" ), 
					li"
					 || Char( idx ) || "= ex" || Char( idx ) ||
					"<< Get Button Name();
					Web Browser Box( Char( \!"https://en.wikipedia.org/wiki/Iris_\!" || li" || Char( idx )
					 || ")
					 
					  )
						 
			
				), 
				
				
					
				
				<<Underline Style( 1 );
			
			)"
				)
			)
		)
	); 
			

	
	
	dt2 << end data update;
	
);
rs = dt2 << make row state handler( f );
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Make row state handler

You will have to somehow remove the old boxes.

 

I'm not sure if this does what you wish it to do, but I did make quite heavy modifications to your script

Names Default To Here(1);

dt2 = Open("$SAMPLE_DATA/Iris.jmp", invisible);
dt2 << Clear Select;

nw = New Window("",
	H List Box(
		Graph Builder(
			Size(653, 571),
			Show Control Panel(0),
			Variables(X(:Sepal length), Y(:Sepal width), Overlay(:Species)),
			Elements(Points(X, Y, Legend(6)))
		),
		Spacer Box(size(10, 0)), 
		Outline Box("Petal Species",
			Spacer Box(size(0, 10)),
			Scroll Box(
				size(350, 150),
				tb_species = Table Box(,<< set selectable rows(0))
			)
		)
	)
);

add_buttons = Function({a},
	selrows = dt2 << get selected rows;
	
	sel_species = Associative Array(dt2[selrows, "Species"]) << get keys;
	
	new_colbox = Col Box("Species");
	
	For Each({cur_species, idx}, sel_species,
		new_colbox << append(
			Button Box(cur_species
				, << Set Function(function({this},
					New Window("Wikipedia", Web Browser Box("https://en.wikipedia.org/wiki/Iris_" || (this << get button name)));
				))
				, << Underline Style(1),
			)
		)
	);
	
	Try(tb_species[ColBox(1)] << Delete Box());
	tb_species << append(new_colbox);
);

rs = dt2 << make row state handler(add_buttons);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Make row state handler

You will have to somehow remove the old boxes.

 

I'm not sure if this does what you wish it to do, but I did make quite heavy modifications to your script

Names Default To Here(1);

dt2 = Open("$SAMPLE_DATA/Iris.jmp", invisible);
dt2 << Clear Select;

nw = New Window("",
	H List Box(
		Graph Builder(
			Size(653, 571),
			Show Control Panel(0),
			Variables(X(:Sepal length), Y(:Sepal width), Overlay(:Species)),
			Elements(Points(X, Y, Legend(6)))
		),
		Spacer Box(size(10, 0)), 
		Outline Box("Petal Species",
			Spacer Box(size(0, 10)),
			Scroll Box(
				size(350, 150),
				tb_species = Table Box(,<< set selectable rows(0))
			)
		)
	)
);

add_buttons = Function({a},
	selrows = dt2 << get selected rows;
	
	sel_species = Associative Array(dt2[selrows, "Species"]) << get keys;
	
	new_colbox = Col Box("Species");
	
	For Each({cur_species, idx}, sel_species,
		new_colbox << append(
			Button Box(cur_species
				, << Set Function(function({this},
					New Window("Wikipedia", Web Browser Box("https://en.wikipedia.org/wiki/Iris_" || (this << get button name)));
				))
				, << Underline Style(1),
			)
		)
	);
	
	Try(tb_species[ColBox(1)] << Delete Box());
	tb_species << append(new_colbox);
);

rs = dt2 << make row state handler(add_buttons);
-Jarmo
Jackie_
Level VI

Re: Make row state handler

Thanks Jarmo! 

 

This is exactly what I want. 

 

Can we re-order columns in the table box?    Nvm I figured it out