0

I am trying to adjust the width of column in jqgrid with the size of text in that column. I didn't find a solution by searching.

I tried the solution at this question: jqgrid column width auto. I have problem with the header now. When there is no horizontal scroll in the jqgrid the header is shorter than the body. Any idea?

Community
  • 1
  • 1
amanda chaw
  • 137
  • 2
  • 14

1 Answers1

0

Some time ago I wrote small jqGrid plugin with setColWidth method. It do what you need. The last version of the method you can download from github (jQuery.jqGrid.setColWidth.js file). In the answer there are an example of usage of the method. Another demo created for the answer demonstrates the usage of the method to set the width of every columns of the grid based on the width of maximal width of content in the column and in the column header.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thank you very much for the answer. I put that in the code. The only issue is that when I add column in the jqgrid by column chooser, some columns texts are cut out. But when I refresh the page it is perfect. – amanda chaw Oct 16 '14 at 03:34
  • I have to mention that I used your answer: http://stackoverflow.com/questions/24322006/jqgrid-column-width-according-to-its-content/24329916#24329916 and have above issue – amanda chaw Oct 16 '14 at 05:08
  • @amandachaw: You should follow [the answer](http://stackoverflow.com/a/25969975/315935) and do recalculation of column width in case of `jqGridRemapColumns` event and not only in case of `jqGridAfterLoadComplete`. See `"jqGridAfterLoadComplete jqGridRemapColumns"` instead of `"jqGridAfterLoadComplete"`. – Oleg Oct 16 '14 at 08:38