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