sarp
sarp

Reputation: 3750

auto-fit columns to their contents with jqGrid

With jqGrid if width of columns are not specified, they share the width of the grid equally. (ie. if the width of grid is 400px and there are 4 columns, they all occupy 100px width). Is there an option to handle this in a smart way so width of the columns can be upon their content?

For example let's say there are two columns: name and info. Assuming average length of names is 60 chars, whereas average length of info is 400 chars. If the grid has a width of 460px, name column should has a width of 60px and info column should has a width of 400px.

Some kind of autowidth-to-content functionality is needed. I think there is a little possibility about that because if I dynamically resize the grid, then the width columns somehow changes and fits according to their contents.

Thanks in advance.

Upvotes: 3

Views: 4810

Answers (1)

Justin Ethier
Justin Ethier

Reputation: 134275

You could dynamically resize the grid in the `loadComplete', to make column width better fit the content. Normally I will just choose column widths that are satisfactory for each row and that tends to be good enough. There is also a method for showing an ellipsis for content that is too wide to fit within a column, although unfortunately the technique is error-prone in firefox.

Upvotes: 1

Related Questions