Forum
12:53
10/08/2009
Hello Tony,
last time you are probably too busy because I receive no feedback from you about my last posts. Nevertheless one more bug with the corresponding fix:
I analysed some problems with wrong width calculation and found out three main reasons for that:
- The width calculation in setColWidth function has some small bugs. There are very close code in setGridWidth which works much better and some problems existing in setColWidth are fixed here.
- On all non-webkit webbrowsers the column width set to the column (from width option of colModel) will be interpret as inner witdth (without border). So if the grid has default setting shrinkToFit:true then the width value of all non-fixed colModel will be imediataly decreased even if there are enough free space for the grid. So from one side the width value of colModel to set inner width of columns, but then change the value as if one set the outer width.
- If the grid has shrinkToFit:true option, in the calculation of the shrinked column size will be used only non-hidden columns. The original column sie from the colModel definition will be ovewritten. If later one make some initially hidden column visible one recalculate the width of every column one more time. Now one use the current reduced size of initially visible columns and compared it with unchanged width of initially hidden column. In the way the proportions between columns will be distorted. I suggest at the begining to save the original value of width property of colMadel items in another property widthOrg and use always the property in the calculations of the shrinked width of columns. In the way the proportions between column widths will stay allways the same as one defined in colMadel independend on the order in which the columns will become visible.
I prepared the corresponding bug fix with changes in setColWidth , ShowHideCol and setGridWidth functions which I will post later today (about 20 lines of code should be changed).
Tony, in which form you desire that I post the changes: here or in github? If I post it in github it will be easy to make exactly this changes, but if I post my suggestions here you can easier to make some changes in the code.
-----------------------------
OK, Tony here are my suggestions:
Changes in the function setColWidth: Line 1868:
after the line 1872-1877 shold be done following:
cw = intNum(this.width,0);
this.widthOrg = cw; // save the original column width
if(this.hidden===false){
initwidth += cw+brd;
if(this.fixed) {
tw += cw;
gw += cw+brd;
} else {
The line 1884 should be deleted:
The line 1899 should be changed:
The line 1914 should be also changed:
Changes in the function ShowHideCol: Line 2789-2791:
return this.each(function() {
var $t = this, fndh=false, brd=$.browser.safari? 0: $t.p.cellLayout, cw;
Line 2805 soll be replaced to the follwoing lines
if(show == "none") { $t.p.tblwidth -= cw;} else {$t.p.tblwidth += cw;}
and the lines 2811-2820 (the boby of the if(fndh===true)) to the following lines:
$($t).jqGrid("setGridWidth",$t.p.tblwidth,true);
} else {
$("table:first",$t.grid.hDiv).width($t.p.tblwidth);
$("table:first",$t.grid.bDiv).width($t.p.tblwidth);
$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
if($t.p.footerrow) {
$("table:first",$t.grid.sDiv).width($t.p.tblwidth);
$t.grid.sDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
}
}
In the body of hideCol and showCol functions the function name ShowHideCol should be replaced to the showHideCol:
return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
},
showCol : function(colname) {
return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
},
Changes in the function setGridWidth: Line 2880 sholuld be changed to
The lines 2903-2906 to
initwidth += cw+brd;
if(this.fixed) {
tw += cw;
gw += cw+brd;
} else {
The lines 2926 should be replaced to the next two lines:
cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
and the line 2946 to
It's all. In many places the value vc*brd+gw will be used: the total width of border of all visible columns (vc*brd) plus the total width of fixed visible columns (gw). One can define one variable like fixedGridWidthPart for the value and use it instead of vc*brd+gw expression.
Moreover if one would make a little more changes in the code one could make it free from cellLayout parameter. The idea is to fill th elements with the width value from the colModel for all visable columns and place the corresponding DOM elements in grid.headers.el before calling of setColWidth. Then inside of setColWidth one could just use jQuery.outerWidth for calculating of the full grid width (totalWidth below) and fixedGridWidthPart:
i=0, headers=mygrid[0].grid.headers, l=headers.length, colModel = ts.p.colModel;
for (;i<l; i++) {
th = headers[i].el;
if (th.style.display !== "none") {
outerWidth = $(th).outerWidth();
totalWidth += outerWidth;
fixedGridWidthPart += cm.fixed? outerWidth: outerWidth - cm.width; //? $(th).width()
}
}
I don't made the corresponding changes to make changes in small steps and test all carefully.
Additionally it would be nice to share the parts of code for width calculation and column shrinking between setGridWidth and setColWidth functions.
Best regards
Oleg
16:45
Moderators
30/10/2007
Hello,
Thanks Oleg, I will look an test your changes right now and will write you for the result
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.
17:13
Moderators
30/10/2007
Oleg,
Please do the changes in GitHub.
To delete a text open the post switch to HTML mode and enter the del tag
Thanks
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.
17:48
10/08/2009
OK I will do this in GitHub.
If I past the text in the forum I always verify and modify in HTML mode, but I found one more strange behavior. Till you posted your reply, the strikethrough text was correctly displplayed. After you posted the answer, the strikethrough text become not more strikethrough but are displyed in another color.
Regards
Oleg
19:03
10/08/2009
I posted my suggestions in GitHub here.
Best regards
Oleg
P.S. If the way is better for you I could make all bug fixes or feature requests with the code in GitHub in the same way. I can additionally post in the Bug forum only my comments to the suggested changes. Schould I post for example this bug report also in the same way?
19:32
Moderators
30/10/2007
Thanks Oleg.
I have merged the fixes.
I prefer to discuss the changes first and then to make the changes.
The chang from the link you provide is already done.
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.
19:47
10/08/2009
OK I see now. You merged the fix more quickly as I posted my comments here. 🙂
Do you read my comment in github to the changes? It seems to me that the change without the line
is not work (see demos).
If you'll find the time to look the suggestion how to fix id duplicates in the pager let me know.
Best regards
Oleg
18:19
10/08/2009
Hi Tony,
I found out that the last version of code at the end of showHideCol work not correct. To fix the problem one should simplify the code inside of if(fndh===true) to the following
if($t.grid.width!==$t.p.tblwidth) {
$($t).jqGrid("setGridWidth",$t.p.shrinkToFit===true?$t.grid.width:$t.p.tblwidth,true);
}
}
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
36 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