Forum
15:57
24/02/2009
Hello,
I am trying to dynamically resize a grid using the "setGridWidth" method. When I call "setGridWidth" on a grid to make the size of the grid smaller, it appears to resize the columns in the grid to fit the new grid width, even if I have "shrinkToFit" set to false. After reading the documentation on shrinkToFit, I expected the column widths to not be changed after the grid was resized.
I really want the column widths to stay their original sizes after setGridWidth is called. Is this a bug, is there some workaround, or am I just not understanding how shrinkToFit works?
Here is an example that reproduces the issue. Clicking the "Click Me" button will resize the grid to a smaller size, causing the columns to resize...
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script src="jquery.js" type="text/javascript"></script>
<script src="custom.js" type="text/javascript"></script>
<script src="jquery.jqGrid.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var mystr = "<?xml version='1.0' encoding='utf-8'?><invoices><rows><row><cell>data1</cell><cell>data2</cell><cell>data3</cell></row><row><cell>data1</cell><cell>data2</cell><cell>data3</cell></row></rows></invoices>";
$("#clickMe").click(function() {
$("#gridContainer").setGridWidth(200, false);
});
$("#gridContainer").jqGrid({
datatype: 'xmlstring',
colNames: ['Id', 'Name', 'Description'],
colModel: [
{ name: 'id', index: 'id', width: 150, resizable: true },
{ name: 'name', index: 'name', width: 200, resizable: true, sorttype: 'text' },
{ name: 'description', index: 'description', width: 250, resizable: true}],
datastr: mystr,
width: 400,
shrinkToFit: false,
imgpath: 'themes/steel/images',
});
});
</script>
</head>
<body>
<p>Here is some text</p>
<table id="gridContainer" class="scroll" cellpadding="0" cellspacing="0" />
<input id="clickMe" type="button" value="Click Me" />
</body>
</html>
Thanks for your help.
-Dave
01:55
Moderators
30/10/2007
Hello,
Also use the second parameter in setGridWidth - see Docs.
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:51
16/03/2009
Hello.
I also have this problem of resizing. I set "shrinkToFit" to false and I called setGridWidth with second parameter = "false". All the columns in colModel have the "width" parameter set. After the resizing of the grid, all the columns are resized too, acording to the new grid size.
The thing that I want to do is to resize the grid and don't resize the columns, so that the horizontal scrollbar appears, and user may scroll and view the full contents of the cells.
Your help will be greatly appreciated.
Best regards
11:09
24/02/2009
tony said:
Hello,
Also use the second parameter in setGridWidth - see Docs.
Regards
Tony
Tony,
According to the docs, the second parameter "has the same behavior as shrinkToFit". The description of "shrinkToFit" in the docs says, "If the value is false and the value in width option is set then: The width of the grid is the width set in option. The column width are not recalculated and have the values defined in colModel."
This "shrinkToFit = false" behavior is what I am trying to get. I don't want the columns to resize whenever I call setGridWidth.
If you look at my code, I am setting the second parameter to "false" on this line...
$(”#gridContainer”).setGridWidth(200, false);
I have tried setting the parameter to "true", but that doesn't do what I want either.
Any help you could give me would be greatly appreciated.
-David
01:40
Moderators
30/10/2007
Hello,
Thanks. If I look into the code right now - there is a really problem with this.
Let me to try to correct this.
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.
05:18
16/03/2009
Hi, I put this matter aside for some time, waiting for some fix. Well, it has not come out yet and I needed the feature. So, I digged in the code and debugged it to try to find the problem.
The problem seems to be in the setGridWidth function. I think the code that has “the problem” is:
[code]
cw = shrink !== true ? $(”tr:first th:eq(”+i+”)”,$t.grid.hDiv).css(”width”) : this.width;
w = Math.floor((IENum(nwidth)-IENum(testdata[2]))/IENum(testdata[0])*IENum(cw));
chw += w;
[/code]
The variable cw seems to be some kind of additional value used when computing the width of the resized column, and if shrik parameter is false, it takes the value from the declared column width.
The problem is the line
[code] w = Math.floor((IENum(nwidth)-IENum(testdata[2]))/IENum(testdata[0])*IENum(cw)); [/code]
, that computes w to be the resized column width, using the above cw as “parameter” value. Even if the testdata[2] variable is set to be 0 when shrink is false, the value w that later is used to set the column width gets an altered value from the original.
So I modified the above code to be :
[code]
cw = shrink !== true ? $(”tr:first th:eq(”+i+”)”,$t.grid.hDiv).css(”width”) : this.width;
w = 0;
if(shrink == true)
{
w = Math.floor((IENum(nwidth)-IENum(testdata[2]))/IENum(testdata[0])*IENum(cw));
}
else
{
w = IENum(cw);
}
[/code]
This way w always gets the original column width, and the column width is not altered.
I think the testdata variable has something to do with the above calculations, but I didn't looked further into this problem. The above modifications solved my issue. The “bad” part is that if you want to modify you have to used the unpacked .js files, or modify it and then repack it again (I don't know how to do that).
I don't claim that the modification that I made solves the issue of shrinkToFit, it is just a minor adjustment that I made so the column width remains the same.
03:20
Moderators
30/10/2007
Hello,
Thanks again. Need to be tested, but I think moving to 3.5 is better.
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.
Most Users Ever Online: 715
Currently Online:
89 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66