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_Related Related Topics sp_TopicIcon
column width auto resize
19/02/2014
21:59
Avatar
bahareeh
Member
Members
Forum Posts: 3
Member Since:
23/10/2013
sp_UserOfflineSmall Offline

How to change the column width dynamically according to the content of that column. Is there a specific widget? I would be thankful if you help me. I tried shrinkToFit and autoWidth but those didn't work for me.

21/02/2014
05:56
Avatar
bahareeh
Member
Members
Forum Posts: 3
Member Since:
23/10/2013
sp_UserOfflineSmall Offline

After some progress, I found that if I change table-layout:fixed to table-layout:auto, the column width will fit with the content of that cell. But when I did that, the header is not aligned with the columns any more. Please help if you can.

10/09/2014
11:31
Avatar
pphillips001
Member
Members
Forum Posts: 4
Member Since:
22/10/2013
sp_UserOfflineSmall Offline

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/09/2014
13:31
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

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.

Forum Timezone: Europe/Sofia

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.com

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

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information