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(‘‘);
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