cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
pmroz
Super User

Set column width with JSL?

Is there a way to set the display width of a column using JSL?  When I create a table, by default the columns are too wide.  I've tried playing around with set column width but it doesn't work.

I know that the column width is stored somewhere, because if I set the column widths manually, save the dataset, and then open it again, voila the widths are preserved.  I just don't know how to do it in JSL.

Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
mattf
Level V

Set column width with JSL?

Hi:

 

 

dt = New Table( "test");
dt << New Column( "new");

column("new") << Get Field Width();  // default 10;

column("new") << Set Field Width(30);

column('new") << Get Field Width(); // now shows 30;

Show Properties(:new);  // log shows  a large number of properties, including field width;

 

 

Hope this helps,

-Matt

View solution in original post

David_Burnham
Super User (Alumni)

Re: Set column width with JSL?

Peter

 

Version 12 has a new column message: Set Display Width.

 

 

Try( Column(dtCopy,"Viable cell density") << Set Display Width(120) ):

Try( Column(dtCopy,"Viable cell density") << Set Display Width(120) );

 

 

Dave

-Dave

View solution in original post

7 REPLIES 7
mattf
Level V

Set column width with JSL?

Hi:

 

 

dt = New Table( "test");
dt << New Column( "new");

column("new") << Get Field Width();  // default 10;

column("new") << Set Field Width(30);

column('new") << Get Field Width(); // now shows 30;

Show Properties(:new);  // log shows  a large number of properties, including field width;

 

 

Hope this helps,

-Matt

pmroz
Super User

Set column width with JSL?

Hi Matt,

 

That works if the column title is short.  However I have longer column names, and it appears that you can't set the field width to anything shorter than the column header.  For example:

 

 

dt = New Table( "test");

dt << New Column( "Curr Serious");

column("Curr Serious") << Get Field Width();  // default 10;

column("Curr Serious") << Set Field Width(30);

column("Curr Serious") << Set Field Width(3); // shrinks the column but not to 3

 

ms
Super User (Alumni) ms
Super User (Alumni)

Set column width with JSL?

For that situation you could use a short dummy name to force the apparent width to obey the field width.

 

 

dt = New Table( "test");
col=dt << New Column( "Curr Serious");
colname=col<<get name;
col << Set Field Width(30);
col<<set name("qqq");  // Any short unused temporary name
col << Set Field Width(3); // shrinks the column but not to 3
col<<set name(colname); // Reset column name, without changing width

 

However, controlling the table appearance by setting the field width property is not a general solution or comparable to manually changing column with by dragging the border. For instance, if the width is set to fewer characters than the cell content "###" or similar is shown instead of the value.

tatarjj
Level I

Re: Set column width with JSL?

I have tried all the suggested solutions in this thread and none of them work.  I am using JMP 13.2.1. 

  1. Set Width does nothing if the column title exceeds the width you are trying to set. 
  2. Set Dispaly Width does nothing if the column title exceeds the width you are trying to set.. 
  3. If I name the column something short like "xxx", set the width to 5, set the display width to 5, and then leave the column named as "xxx" then the column width stays narrow.  However, as soon as I use the code column("xxx") << Set Name("Some long column name"); then the width of the column expands to try to (unsuccessfully) fit the column name.

So, the original question remains: does JMP have a way to set the column width using JSL, or do I have to manually adjust the column widths on these hundreds of columns and dozens of JMP files myself?  It's real easy to tell someone to "just do it manually" when you're not the one having to do it hundreds of times across dozens of files. :(

robust1972
Level IV

Re: Set column width with JSL?

hi, Matt

Can I set the column width to fit the longest title and cell content for few columns? Recently I tried to color the cells to draw wafer maps but I have to manually adjust the width of columns.

Thanks!

erin_vang
Level II

Re: Set column width with JSL?

This little expression will set the display width to suit the width of the longest values in all the character columns of a data table, within the min and max widths you set, by using an average character width that you can also set. Typically numeric columns have good widths by default, so changing those also is left as an exercise for the reader. I thought this routine would be punishingly slow for large data tables, so I didn't bother to write it before today, but it turns out to be pretty quick, taking only a few seconds to run on a data table with over 200K rows on 22 character columns. 

 

xpr_resizeCols = Expr(
	Local( {list_widths, list_colNames, num_length, num_charWidth,num_maxWidth, num_minWidth },
		num_charWidth = 6.5; // set number of pixels per character's average width
		num_maxWidth = 400; // set maximum desirable column width
		num_minWidth = 45; // set miniumum desirable column width
		list_widths = {};
		list_colNames = Current Data Table() << get column names( character );
		For( i = 1, i <= N Items( list_colNames ), i++, // i = 1
			list_temp = list_colNames[i] << get values;
			num_length = 0;
			For( j = 1, j <= N Items( list_temp ), j++,
				If( Length( list_temp[j] ) > num_length,
					num_length = Length( list_temp[j] )
				)
			);
			Try( list_colNames[i] << set display width( Max( num_minWidth, Min( num_maxWidth, num_length * num_charWidth ) ) ) );
			Insert Into( list_widths, num_length * num_charWidth );
		);
	);
	Write(
		"\!N\!tColumns resized to fit contents, within limits " || Char( num_minWidth ) || " to " || Char(  num_maxWidth ) ||
		" pixels."
	);
);

Global Pragmatica LLC® is a USA-based JMP customization partner, offering custom JSL and JMP add-in work for hire; please feel free to contact me at [erin dot vang at globalpragmatica dot com] if you'd like to discuss a project. 


Erin Vang
Principal Pragmatist, Global Pragmatica LLC® - Custom JMP Scripting
David_Burnham
Super User (Alumni)

Re: Set column width with JSL?

Peter

 

Version 12 has a new column message: Set Display Width.

 

 

Try( Column(dtCopy,"Viable cell density") << Set Display Width(120) ):

Try( Column(dtCopy,"Viable cell density") << Set Display Width(120) );

 

 

Dave

-Dave