Forum
11:31
22/10/2013
I don't know if you managed to find a solution, however here is my approach to variable column widths based on column contents.
Add this to the gridComplete event :
$(this).parent().append('<span id="widthTest" />');
gridName = this.id;
$('#gbox_' + gridName + ' .ui-jqgrid-htable,#' + gridName).css('width', 'inherit');
$('#' + gridName).parent().css('width', 'inherit');var columnNames = $("#" + gridName).jqGrid('getGridParam', 'colModel');
var thisWidth;// Loop through Cols
for (var itm = 0, itmCount = columnNames.length; itm < itmCount; itm++) {var curObj = $('[aria-describedby=' + gridName + '_' + columnNames[itm].name + ']');
var thisCell = $('#' + gridName + '_' + columnNames[itm].name + ' div');
$('#widthTest').html(thisCell.text()).css({
'font-family': thisCell.css('font-family'),
'font-size': thisCell.css('font-size'),
'font-weight': thisCell.css('font-weight')
});
var maxWidth = Width = $('#widthTest').width() + 24;
//var maxWidth = 0;// Loop through Rows
for (var itm2 = 0, itm2Count = curObj.length; itm2 < itm2Count; itm2++) {
var thisCell = $(curObj[itm2]);$('#widthTest').html(thisCell.html()).css({
'font-family': thisCell.css('font-family'),
'font-size': thisCell.css('font-size'),
'font-weight': thisCell.css('font-weight')
});thisWidth = $('#widthTest').width();
if (thisWidth > maxWidth) maxWidth = thisWidth;
}$('#' + gridName + ' .jqgfirstrow td:eq(' + itm + '), #' + gridName + '_' + columnNames[itm].name).width(maxWidth).css('min-width', maxWidth);
}
$('#widthTest').remove();
Â
Here's a working example :Â http://jsfiddle.net/Ba5yK/17/
Regards,
Â
Paul
13:31
Moderators
30/10/2007
Hello,
Â
Thanks for posting this solution.
Â
Best Regards
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:
41 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