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_TopicIcon
Auto-sizing the columns
10/11/2009
09:43
Avatar
friflaj
Member
Members
Forum Posts: 17
Member Since:
09/11/2009
sp_UserOfflineSmall Offline

Is there a way (by config or by jquery code) to set the column widths to reasonable defaults, much like the regular html table behaves when you don't set any explicit column widths?

11/11/2009
03:22
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Many times disscused - the answer is No.

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.

11/11/2009
04:46
Avatar
friflaj
Member
Members
Forum Posts: 17
Member Since:
09/11/2009
sp_UserOfflineSmall Offline

I take that as a challenge ;)

I'm getting closer: I can calculate an approximation of the width for a specific column by finding the width of, for example, the first cell:

<div id=”measure” style=”visibility:hidden”/>

and in loadComplete:

$('#measure').html('<span>' + $('#treegrid2 tbody tr:first td:eq(1)').text() + '</span>');

alert($('#measure span').width());

I realize that the cell selection should use getCell, but that always returns false for me, I'll keep poking at that. So how do I use this width value to set the width of a column after load? Between http://www.trirand.com/jqgridw.....;s=getcell I don't see anything that fits the bill.

12/11/2009
10:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

You should consider my answer NO as challenge too Wink

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.

13/11/2009
08:02
Avatar
friflaj
Member
Members
Forum Posts: 17
Member Since:
09/11/2009
sp_UserOfflineSmall Offline

I'm currently looking at something like this (call with resizeColumns('#yourgrid', ['colname1', 'colname2']):

    function resizeColumns(id, cols) {
        var grid = $(id);
        var cfgstring = grid.jqGridExport({'exptype': 'jsonstring'});
        //var config = JSON.parse(cfgstring, function(k, v) { return v; });
        eval('config = ' + cfgstring);
        var rows = grid.getRowData();
        var widths = new Array();
        for (col in cols) {
            colname = cols[col];
            widths[colname] = 0;
        }

        for (rownum in rows) {
            row = rows[rownum];
            for (col in cols) {
                colname = cols[col];
                $('#measure').html('<span>' + row[colname] + '</span>');
                w = $('#measure span').width();
                if (w > widths[colname]) {
                    widths[colname] = w;
                }
            }
        }

        var colModel = config['grid']['colModel'];
        for (col in colModel) {
            if (colModel[col]['name'] in widths) {
                colModel[col]['width'] = widths[colModel[col]['name']];
            }
        }
        grid.jqGridImport({'imptype':'jsonstring', 'impstring':JSON.stringify(config)});
    }

Currently, jqGridExport({'exptype': 'jsonstring'}) throws an error:

Error: $t.p.colModel[i] is undefined
Source File: http://projecten.han-imao.nl:8000/agilito/js/jquery.jqgrid/js/jquery.jqGrid.min.js
Line: 10

I know the eval is stupid, but when I use JSON.parse I just get

Error: JSON.parse
Source File: http://projecten.han-imao.nl:8000/3/iteration/62/
Line: 223

Any clues appreciated.

17/11/2009
00:31
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

If you try this with FireFox 3.5 on Linux or FireFox and Safary on Mac there is a bug which is corrected - also it is not actually a bug in jqGrid, but in FireFox.

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/11/2009
06:38
Avatar
friflaj
Member
Members
Forum Posts: 17
Member Since:
09/11/2009
sp_UserOfflineSmall Offline

I see. So this is not likely to be a useful approach for the short term. Is there a workaround?

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
75 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