cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
itzikd
Level II

color TableBox rows

I have a table box that has text but also buttons and I want to color it it more then 1 color

 

col1 = {1, 2, 3};
col2 = {1, 2, 3};
col3 = {1, 2, 3};
myPlatform = New Window( "test",
	tb = Table Box(
		Number Col Box( "a", col1 ),
		Number Col Box( "b", col2 ),
		Number Col Box( "c", col3 ),
		bb = Col Box( "Open Graph" )
	)
);


bblist = {};
For( i = 1, i <= 3, i++,
	bb_expr = Eval Insert( "\[bblist[i] = buttonbox("ok")]\" );
	Eval( Parse( bb_expr ) );
	bb << append( bblist[i] );
);

tb << Set Selectable Rows(1);
dt = tb << Make into Data Table( invisible );
rs = dt << Get Rows Where( :a > 1 );
tb << Set Selected Rows( rs );
tb << Set Selected Row Color( "red" );
rs = dt << Get Rows Where( :a == 1 );
tb << Set Selected Rows( rs );
tb << Set Selected Row Color( "green" );

The problem is that if I remove the last 2 lines, it colors the last 2 lines in red, but if I do run the last 2 lines, it removes the red color and colors in green the top line instead of leaving the red color as well

 

before running last 2 lines:

itzikd_0-1619595029444.png

 

after running last 2 lines

itzikd_1-1619595059193.png

 

 

is there a way to color the table box in more then 1 color? (I want it to have both red and green colors)

I tried working with journal as well, but then I'm not sure how to add the buttons.

 

thanks!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: color TableBox rows

I had one script where I wanted to do something similar (in the end I gave up with it and went with different approach for the application, because it got a bit too complicated for my taste for no reason).

 

I modified it a bit and this will get you the basic window:

Names Default To Here(1);
dt = New Table("Untitled",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("a",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([1, 2, 3])
	),
	New Column("b",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([2, 2, 3])
	),
	New Column("c",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([2, 2, 3])
	),
	invisible
);

dt << Select Where(:a > 1);
For(i = 1, i <= N Cols(dt), i++,
	Column(dt, i) << Color Cells("Red");	
);
dt << Clear Select;

dt << Select Where(:a == 1);
For(i = 1, i <= N Cols(dt), i++,
	Column(dt, i) << Color Cells("Green");	
);
dt << Clear Select;
rep = dt << get as report;
Close(dt, no save);
nw = New Window("Example", 
	hlb = h list box()
);
rep << append(Col Box("Open Graph", Button Box("ok"),Button Box("ok"),Button Box("ok")));
hlb << append(rep);
tb = (hlb << XPath("//TableBox"))[1];
tb << Set Scrollable(5,5);

Idea was to color the datatable, get the datatable as report, add buttons to that report and finally append that to new window (and resize).

-Jarmo

View solution in original post

jthi
Super User

Re: color TableBox rows

Not completely sure what is wrong there (could be that Col Box() wouldn't take list as argument as it seems to need comma separated display boxes). But this could be one way to do it:

bblist = Expr(col box("Open Graph"));
For( i = 1, i <= 3, i++,
	Insert Into(bblist, buttonbox("test"||char(i)));
);

rep << append(bblist);
hlb << append(rep);
-Jarmo

View solution in original post

6 REPLIES 6
itzikd
Level II

Re: color TableBox rows

even if you can't do it with table box, is there another way to do this? the problem is that i need to add the buttons to it as well somehow
jthi
Super User

Re: color TableBox rows

I had one script where I wanted to do something similar (in the end I gave up with it and went with different approach for the application, because it got a bit too complicated for my taste for no reason).

 

I modified it a bit and this will get you the basic window:

Names Default To Here(1);
dt = New Table("Untitled",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("a",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([1, 2, 3])
	),
	New Column("b",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([2, 2, 3])
	),
	New Column("c",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([2, 2, 3])
	),
	invisible
);

dt << Select Where(:a > 1);
For(i = 1, i <= N Cols(dt), i++,
	Column(dt, i) << Color Cells("Red");	
);
dt << Clear Select;

dt << Select Where(:a == 1);
For(i = 1, i <= N Cols(dt), i++,
	Column(dt, i) << Color Cells("Green");	
);
dt << Clear Select;
rep = dt << get as report;
Close(dt, no save);
nw = New Window("Example", 
	hlb = h list box()
);
rep << append(Col Box("Open Graph", Button Box("ok"),Button Box("ok"),Button Box("ok")));
hlb << append(rep);
tb = (hlb << XPath("//TableBox"))[1];
tb << Set Scrollable(5,5);

Idea was to color the datatable, get the datatable as report, add buttons to that report and finally append that to new window (and resize).

-Jarmo
itzikd
Level II

Re: color TableBox rows

thanks! this helps a lot!

but what if I want to create buttons dynamically

 

bblist = {};
For( i = 1, i <= 3, i++,
	bb_expr = Eval Insert( "\[bblist[i] = buttonbox("test")]\" );
	Eval( Parse( bb_expr ) );
	bb << append( bblist[i] );
);

when I try to do

rep << append(Col Box("Open Graph", bb));

it doesn't work

 

any suggestion?

jthi
Super User

Re: color TableBox rows

Not completely sure what is wrong there (could be that Col Box() wouldn't take list as argument as it seems to need comma separated display boxes). But this could be one way to do it:

bblist = Expr(col box("Open Graph"));
For( i = 1, i <= 3, i++,
	Insert Into(bblist, buttonbox("test"||char(i)));
);

rep << append(bblist);
hlb << append(rep);
-Jarmo
itzikd
Level II

Re: color TableBox rows

thanks! this helps a lot

I have 1 last question:

 

using this code, I'm trying to create for each button a different value in the function.

so in this example if I click button 1 it should print 1, if I click 2 it should print 2 and so on..

but for some reason the value doesn't "stick" and any button I click it says 4.(4 is the number of i after the loop ends)

 

Names Default To Here(1);
dt = New Table("Untitled",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("a",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([1, 2, 3])
	),
	New Column("b",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([2, 2, 3])
	),
	New Column("c",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([2, 2, 3])
	),
	invisible
);

newFunc = function({i},
	print(i);
);

dt << Select Where(:a > 1);
For(i = 1, i <= N Cols(dt), i++,
	Column(dt, i) << Color Cells("Red");	
);
dt << Clear Select;

dt << Select Where(:a == 1);
For(i = 1, i <= N Cols(dt), i++,
	Column(dt, i) << Color Cells("Green");	
);
dt << Clear Select;
rep = dt << get as report;
Close(dt, no save);
nw = New Window("Example", 
	hlb = h list box()
);
bblist = Expr(col box("Open Graph"));
For( i = 1, i <= 3, i++,
	Insert Into(bblist, buttonbox("test"||char(i),newFunc(i)));
);

rep << append(bblist);
hlb << append(rep);
tb = (hlb << XPath("//TableBox"))[1];
tb << Set Scrollable(5,5);

is there a way to fix this? 

 

 

jthi
Super User

Re: color TableBox rows

You can easily check what is the issue by using Set Script on one of the buttons from the window that opens:

jthi_0-1620026941571.png

 

i is the argument when it should be the number. You could go with Eval(Parse()) way to fix it:

 

For( i = 1, i <= 3, i++,
	Insert Into(bblist, Eval(Parse("buttonbox(\!"test"||char(i)||"\!",newFunc("||char(i)||"))")));
);

Or Eval(Eval Expr()):

 

 

For( i = 1, i <= 3, i++,
	Eval(EvalExpr(Insert Into(bblist, buttonbox("test"||char(expr(i)),newFunc(expr(i))))));
);

You want the Set Script to look like this (at least in this case):

jthi_1-1620027253658.png

 

"Best" way to do this will most likely be highly application dependant.

 

-Jarmo