0

i have a function where i manually set the width of a jqgrid column. If I after this want to use the resize handle, it adds or substracts relative from the original width size. So it doesn't see my new width to take as a base. I have tried putting the width and withOrg in the colModel without success.

I have a click handler inwhich i resize a column to a certain width on click. i set the width of the th trought JS. After this i would like to be able to use the .ui-jqgrid-resize element for resizing the column.

a short version of my code, say the th is 200px wide:

$('th').dblclick(function(){
   $(this).width('100px');
});

after the user doubleclicked, and the th went smaller in size to 100px, the user uses the resize handle to widen the th 10px. The expected result is a th of 110px wide, but the thjumps to 210px wide. It adds the 10px the user wanted to add to the original state, not the state i have set with the doubleclick.

Laurens Kling
  • 2,221
  • 1
  • 21
  • 31
  • What you mean under "i manually set the width of a jqgrid column" and "after this want to use the resize handle"? What you do exactly and in which context? How you "manually set the width" of the column? Do you write the code of your callback `resizeStop` and need have some additional information? – Oleg Oct 17 '14 at 14:17
  • does the question update help? – Laurens Kling Oct 17 '14 at 14:53
  • Sorry, but I still don't understand your **goals**. You wrote "i would like to be able to use the .ui-jqgrid-resize element". It can't be your goal. You can any time "use the element", but what you want to implement? Why you "set the width of the th"? jqGrid did it already. What you want *additionally* to resize *after* the user resized the column? – Oleg Oct 17 '14 at 15:04
  • after the column width has been manually reset, the size change by the resize handle is off. it does not resize relative from the current (manually set) width, but from the width it was before i manually set it. Say the width is 100px, i manually change it to 200px, dragging the handle 10px to the right will make the column jump back to 110px wide, not 210px. – Laurens Kling Oct 17 '14 at 15:06
  • Sorry, but I can't follow you. You wrote frequently "i manually set it", "i manually change it". I don't understand what you mean. If you are developer then *the user* could resize the column width and you can write some additional JavaScript code which will be executed after that. For example you can write your code inside of `resizeStop` callback. If the column size was 100px and the user *explicitly increased it to 110px* then why it should be changed to 210px? I see no sense here. Probably if you would append your question with some code which you use one could understand you better. – Oleg Oct 17 '14 at 15:14
  • I've updated my question oleg, hope it helps – Laurens Kling Oct 20 '14 at 08:02
  • Could you explain **what you try to implement**? What you do is definitively wrong. jqGrid have a lot of internal tables. Some from the tables contains `` elements. If you use [filterToolbar](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching#installation) or [setGroupHeaders](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:groupingheadar) you will have many `` elements which have another meaning. Moreover **one can't change the width of column by setting width of the `th` element**. Probably [the old answer](http://stackoverflow.com/a/20030652/315935) can help you – Oleg Oct 20 '14 at 08:17
  • ofcourse i do not set it directly to every `th`; it's an example. And i set the width of both the column `th` and the column in `.jqgfirstrow`. The width is counted within my code. I do this to count the width of the longest data in the column, so doubleclicking the columnheader will make the column wider to let the content fit. After this the resize handle should still work as intended. But this adds the dragged pixels to the old width state, instead of relative from this new state – Laurens Kling Oct 20 '14 at 09:48
  • It's not enough to set `width` of the column `th` and the column in first row of grid `.jqgfirstrow`. There are *other* internal structures which need be updated too (`width` of `colModel`, `width` of `$("gridId")[0].grid.headers[i]` and so on). It was the reason why I wrote `setColWidth` and `autoWidthColumns` (especially the last one is not yet final in my opinion). Look at [the answer](http://stackoverflow.com/a/24329916/315935) and [the demo](http://www.ok-soft-gmbh.com/jqGrid/AutowidthColumn1.htm). – Oleg Oct 20 '14 at 10:09

1 Answers1

0

I would recommend you to use setColWidth method, from the plugin which I wrote before (see the answer), to change the width of the grid column. You can download the current version of the plugin from github.

If you trying to set the width of columns based on the width of the content of the column then I would recommend you to take a look at the demo created for the answer and read the answer too. I don't see the suggested code as final solution, but the demos shows my view on the problem and the ways to implement "autowidth" functionality.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • using the `setColWidth` method does do the trick, can you explain to me why? Is it the dragEnd? – Laurens Kling Oct 20 '14 at 11:42
  • 1
    @LaurensKling: As I wrote you before one need change many internal structures of jqGrid for changing column width. If the user resize the column then tree methods `dragStart`, `dragMove` and `dragEnd` will be called. [dragEnd](https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L911-L946) uses some properties as input (which sets `dragStart`, `dragMove`). So I just fill the same input properties and then call `dragEnd` which is accessible (see [here](https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L2928)) via `this.grid`. It's the best way which I found. – Oleg Oct 20 '14 at 12:32