Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to stretch columns
06/10/2009
08:49
Avatar
HoSpiTaL_gHoSt
Guest
Guests

Hello,

I'm using jqgrid 3.5.2 with shrinkToFit=false and I would like to keep it that way.  My jqgrid is as wide as the webpage, and when the grid has a lot of columns, I get a horizontal scrollbar, which is what I want. My jqgrid resizes when I resize the window, and my column widths stay the same, which is also what I want.

Now the problem is that when I have very few columns, let's say 4, my grid is a lot wider than the total width of the 4 columns and it doesn't look very nice. I would like the columns to be stretched to fit the grid width ONLY when their total width < grid width. Is this possible, and if so how?

Thanks in advance!

07/10/2009
02:47
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Maybe you need to use a setGridWidth method. Also before this you will need to determine the width of the visible columns.

You can do this using getGridParam method something like:

var model = $("#mygrid").getGridParam("colModel");

var visiblewidth = 0;

$.each(model,function(){

if (!this.hidden) visiblewidth += pareseInt(this.width);

});

Hope this help.

Regards
Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

07/10/2009
03:21
Avatar
HoSpiTaL_gHoSt
Guest
Guests

Thanks for the reply. I tried your code, but it makes my grid as wide as the sum of the columns, but I want the opposite, i want the grid width to stay the same, but each column should stretch to "fill" the grid.

I'm not very familiar with jQuery, so I tried out some things in regular Javascript:

                var header = document.getElementsByTagName("th");

                var totaal = 0;
                for(i=0; i <header.length; i++){
                    var width = header[i].style.width;
                    totaal += parseInt(width.substr(0,width.length-2));
                }
               
                var gridWidth = $('#mailinfoGrid').getGridParam("width");
               
                if(totaal < gridWidth){
                    for(i=0; i < header.length; i++){
                        header[i].style.width = Math.floor(gridWidth/header.length) + 'px';
                    }
                   
                    var cells = document.getElementById("gview_mailinfoGrid").getElementsByTagName("td");
                    for(i=0; i &lt; cells.length; i++){
                        cells[i].style.width = Math.floor(gridWidth/header.length) + 'px';
                    }
                }

This code does what I want, but when you then try to resize the columns, the resize "drag line" is in the wrong location.

So based on your example I tried the following code to change each column width to a static value, but the column widths aren't changed?

              if(totaal < gridWidth){
                    $.each(model,function(){
                        if (!this.hidden) {
                            this.width = 200;
                        }
                    });
                }

07/10/2009
04:00
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

No need to do this just call setGridWidth method with the second parameter set to true. See docs

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

07/10/2009
04:26
Avatar
HoSpiTaL_gHoSt
Guest
Guests

I tried that, and because the width of my grid has to stay the same, I just have to get the gridWidth and then set it again, but with shrinkToFit=true:

var gridWidth = $('#mailinfoGrid').getGridParam("width");
$('#mailinfoGrid').setGridWidth(gridWidth,true);

But this doesn't stretch the columns 🙁 it does nothing! It's really weird, but I think it's because shrinkToFit is initially set to false on construction of my jqgrid

07/10/2009
04:31
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

var gridWidth = parseInt($('#mailinfoGrid').getGridParam(”width”));
$('#mailinfoGrid').setGridWidth(gridWidth+0.01,true);

The grid does not change if you try to set the same width (A bug wich will be corrected soon);

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

07/10/2009
04:32
Avatar
HoSpiTaL_gHoSt
Guest
Guests

I tried something else, the only difference is that I get the old grid width and I set the new grid width to the old value -1. This does stretch the columns. I think because I set the width to the same width it had before, the columns didn't stretch. Weird, but it works now!

var gridWidth = $('#mailinfoGrid').getGridParam("width");
$('#mailinfoGrid').setGridWidth(gridWidth-1,true);

07/10/2009
04:33
Avatar
HoSpiTaL_gHoSt
Guest
Guests

tony said:

var gridWidth = parseInt($('#mailinfoGrid').getGridParam(”width”));
$('#mailinfoGrid').setGridWidth(gridWidth+0.01,true);

The grid does not change if you try to set the same width (A bug wich will be corrected soon);


Lol, I just discovered it when you posted the solution! Thanks a lot for your help!

26/10/2009
12:18
Avatar
Hannes Käufler
Guest
Guests

Hi Tony!

Have you gotten around to fixing this bug yet? It still occurs to me with the Git 3.5.3 Version.

Greeting, Hannes

27/10/2009
03:53
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Will try to fix it, because of the new method gridResize.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
83 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information