1

I have an issue when I'm clicking first time to column's span-resizer --> column width returns to some default calculated value. The same thing appears when I'm trying to resize it: it resizes not from current width, but from that calculated!

This shows my table after page load: columns' width are good. screenshot after page load

But after clicking to resize State column --> it's just returns to some value (in that case screenshot after click on column resize

How can I fix this issue?

P.S. Sorry, I have no enough rep to add images.

1 Answers1

0

jqGrid hold column header and the column data in separate dives. So jqGrid have to hold scroll position of the header div (hDiv) the same as the scroll position of the div with the grid body (bDiv). I think that jqGrid have a bug in your situation. As the workaround you can use resizeStop where one set the scroll position of hDiv to the current scroll position of bDiv:

resizeStop: function () {
    this.grid.hDiv.scrollLeft = this.grid.bDiv.scrollLeft;
}

I think that it should solve the problem.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • No, maybe you don't understand my problem: it's not in resizing by mouse, but in setting it to default values. On UI it shows correctly, until I click 'resizer'. Why do it sets it's default values, in case of the table already has it's own columns' width calculated by a different function? I prefer, to set jqGrid's default columns' width to values from the document, but not '150px' as it written in source `if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }` – Andrey Carter Nov 14 '14 at 10:48
  • @Carter: Sorry, but I can't follow you. You should explain which "resizer" and which "default values" you mean. I suppose that you set columns' width in some wrong way. jqGrid set column width based on the value of `width` property of `colModel`. If you don't specify any `width` then it will be set to 150. If you need to use any other value you should set it explicitly. To set default value to 100px for example you can use the following jqGrid option `cmTemplate: { width: 100 }`. It will set `width` property in all column where it is not specified to `100`. – Oleg Nov 14 '14 at 10:58
  • I'm sorry, I'm just a newbie in JS, but I've understood what you mean. Thanx, I'll try it. – Andrey Carter Nov 14 '14 at 11:12
  • @Carter: You are welcome! Let me know whether the problem will be solved. – Oleg Nov 14 '14 at 11:21
  • you've written "If you don't specify any width then it will be set to 150", so how could I specify it, even when I'm trying to set it from my function. – Andrey Carter Nov 14 '14 at 13:15
  • @Carter: I wrote you before that you should use `cmTemplate: { width: 100 }` [option](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options) of jqGrid to use `100` instead of `150` as the default value of `width` property. If you would not solve your problem you should append the text of your question with JavaScript code which you use. – Oleg Nov 14 '14 at 13:25
  • I mean, I don't want use constant, but existing value from other function. I've tried many times, but still don't know how to set it. So I had `dataWidths[]` with calculated by my function widths, and I want to set THIS values to each `colModel[i].width`. I'm sorry for newbietity :) – Andrey Carter Nov 14 '14 at 13:48
  • @Carter: **I can't help you if you explain me your code.** You should append your question with the code or the code fragments. – Oleg Nov 14 '14 at 13:51
  • Thanx, it seems that i've found where was my mistake. Yeap, it depends on `resizeStop` also. – Andrey Carter Nov 14 '14 at 14:11
  • i'm sorry for troubling you, but I have one more question (our QAs sad that my solution "isn't working they expected"): maybe, how could I set the values of [`headers`](https://github.com/tonytomov/jqGrid/blob/master/js/jquery.jqGrid.js#L2602). As I understand, they want this `headers[i].width` values be the same, as after page loaded and columns widths were set. I can give you my html-file, then you maybe understand what I mean. (i'm really newbie in js, so i do not even know where and how could i set this values, so i'll be very thankful to you for ur help) – Andrey Carter Nov 15 '14 at 15:25
  • @Carter: Sorry, but I'm not understand your question. `headers` are internal structures of jqGrid which will be used during resizing of the columns. Probably you want to change the width of the columns *after* the grid created. In the case you can use `setColWidth` method which I published as jQuery plugin [here](https://github.com/OlegKi/jqGrid-plugins/blob/master/jQuery.jqGrid.setColWidth.js). See the description in [the answer](http://stackoverflow.com/a/20030652/315935). – Oleg Nov 15 '14 at 19:24
  • Yeeeah! It's really what I want! Thanx! Respect you :) – Andrey Carter Nov 17 '14 at 07:20