1

unfortunately I can't find any help concerning to my specific problem. I try to simplify it:

My grid consists of a shown column (A) and a hidden column (B) and other shown columns as well (C,D). With a custom button I can switch between these two columns, so that A is hidden and B is shown and vice versa.

My aim is as follows:

If the width of (shown) A has been changed, the width of (hidden) B should also be changed.

My current way to realize this this:

resizeStop: function () {
    var  $self = $(this);
    shrinkToFit = $self.jqGrid("getGridParam", "shrinkToFit");
    $self.jqGrid("setGridWidth", this.grid.newWidth, shrinkToFit);

    var a = $self.jqGrid("getGridParam","colModel");
    $self.jqGrid("setColWidth", "customers.name_short",a[2].width);

},

I works, but I have to wait for a wile and in addition to that I get the following log: "too much recursion". It seems that the function setColWidth is called more than 300 times.

I analyzed the code of setColWidth but I could not find any hint where it would call itself.

Can anybody help me? Thanks in advance!

Oleg
  • 220,925
  • 34
  • 403
  • 798
gnanr
  • 15
  • 5

1 Answers1

0

I suppose that you use my method setColWidth from here and the answer. It's wrong to use it inside of resizeStop callback.

You wrote: "With a custom button I can switch between these two columns, so that A is hidden and B is shown and vice versa." It seems to me that you need place one call of setColWidth method directly after you makes the column A or the column B visible (in the click event handle of your custom button). It should solve the problem.

UPDATED: The following demo http://jsfiddle.net/OlegKi/m7f9ghwq/18/ demonstrates the approach.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • After placing setColWidth as you have said, it works nearly fine. Only one odd side effect occurs which is hard to describe: First step -> Resizing column A to width x; Second step -> clicking the custom button in order to show B and hide A, B gets width x but is presented bigger than A before; Third step -> clicking again shows A and hides B, A with width x is now equally presented to B (also bigger than the resized A). I hope that this description is graspable for you? – gnanr Oct 15 '14 at 14:12
  • @gnanr: You need provide the demo in [jsfiddle](http://jsfiddle.net/) for example, which can be used to reproduce he problem. – Oleg Oct 15 '14 at 14:46
  • Hi Oleg, thank you for your advice. I reproduced the odd behavior in jsFiddle: http://jsfiddle.net/gnanr/m7f9ghwq/11/ – gnanr Oct 16 '14 at 15:36
  • @gnanr: The problem can be fixed by usage `height: "auto"`. See http://jsfiddle.net/OlegKi/m7f9ghwq/12/. I made more changes the code. For example the variable shrinkToFit was used as GLOBAL inside of resizeStop in your original demo. I added `gridview: true, autoencode: true` options, made `bShuffle` associated with the grid so many grids on the page can be used, changed the code of `onClickButton` etc. – Oleg Oct 16 '14 at 16:27
  • On the one hand the problem remains when resizing column A and then switching between A and B. This is the problem. On the other hand the grid's height must not be automatically generated. – gnanr Oct 17 '14 at 16:09
  • @gnanr: Sorry, but I can't invest many time in the problem because of many TODOs on my main job. Nevertheless I made one more demo http://jsfiddle.net/OlegKi/m7f9ghwq/18/ which works. I fixed one line of the code of `setColWidth` (setting of `grid.newWidth`), used explicitly the last 4.6.0 version of jqGrid (instead of 4.5.2 in your demo) and used `shrinkToFit: false` option of jqGrid (which probably not so important). – Oleg Oct 19 '14 at 18:00
  • @gnanr: Do you tried [my last demo](http://jsfiddle.net/OlegKi/m7f9ghwq/18/)? Does it solves your problem? – Oleg Oct 28 '14 at 09:42
  • Hi Oleg, I could not try it because I am on holidays actually. On next monday I will try it as soon as possible. But it looks very good. – gnanr Oct 28 '14 at 14:34
  • @gnanr: Are you back from the holidays? Is the problem is solved? – Oleg Nov 13 '14 at 08:16
  • Hi Oleg, yes I am back but there was no time to test until now. I will give you feedback as soon as possible. Thank you for your helpful assistance! – gnanr Nov 17 '14 at 05:30
  • Hi Oleg, it works in a perfect manner! How can i spend you a big beer? – gnanr Nov 17 '14 at 08:46
  • @gnanr: You are welcome! I'm glad that I could help you. If you want, you can send me "a beer" via PayPal to oleg.kiriljuk@googlemail.com – Oleg Nov 17 '14 at 09:42