0

I am having JQGrid this way,

<div id="parent" class="resizable">
    <table id="grid"></table>    
</div>

    var data = [[48803, "DSK1", "", "002200220", "OPEN"], [48769, "APPR", "", "777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895777333373457892349058723895", "ENTERED"]];

$("#grid").jqGrid({
    datatype: "local",
    height: 250,
    colNames: ['Inv No', 'Thingy', 'Blank', 'Number', 'Status'],
    colModel: [{
        name: 'id',
        index: 'id',
        width: 60,
        sorttype: "int",
        formatter:function(cellvalue, options, rowObject) {return '<div></div><span style="max-height: 63px;">'+cellvalue+'</span>';}
    },    
    {
        name: 'thingy',
        index: 'thingy',
        width: 90,
        sorttype: "date"},
    {
        name: 'blank',
        index: 'blank',
        width: 30},
    {
        name: 'number',
        index: 'number',
        width: 80,
        sorttype: "float",
        formatter:function(cellvalue, options, rowObject) {return '<div></div><span style="max-height: 63px;">'+cellvalue+'</span>';}},
    {
        name: 'status',
        index: 'status',
        width: 80,
        sorttype: "float"}
    ],
    caption: "Stack Overflow Example",   
            gridComplete: function () {
            var grid = $("#grid");          
            resizeGrid1();
    },
});

var names = ["id", "thingy", "blank", "number", "status"];
var mydata = [];

for (var i = 0; i < data.length; i++) {
    mydata[i] = {};
    for (var j = 0; j < data[i].length; j++) {
        mydata[i][names[j]] = data[i][j];
    }
}

for (var i = 0; i <= mydata.length; i++) {
    $("#grid").jqGrid('addRowData', i + 1, mydata[i]);
}

function resizeGrid1() {
    $.jgrid.extend({
        setColWidth: function (iCol, newWidth, adjustGridWidth) {
            return this.each(function () {
                var $self = $(this), grid = this.grid, p = this.p, colName, colModel = p.colModel, i, nCol;
                if (typeof iCol === "string") {
                    // the first parametrer is column name instead of index
                    colName = iCol;
                    for (i = 0, nCol = colModel.length; i < nCol; i++) {
                        if (colModel[i].name === colName) {
                            iCol = i;
                            break;
                        }
                    }
                    if (i >= nCol) {
                        return; // error: non-existing column name specified as the first parameter
                    }
                } else if (typeof iCol !== "number") {
                    return; // error: wrong parameters
                }
                grid.resizing = { idx: iCol };
                grid.headers[iCol].newWidth = newWidth;
                grid.newWidth = p.tblwidth + newWidth - grid.headers[iCol].width;
                grid.dragEnd();   // adjust column width
                if (adjustGridWidth !== false) {
                    $self.jqGrid("setGridWidth", grid.newWidth, false); // adjust grid width too
                }
            });
        }
    }); 

} 

enter image description here

When I have long data input for a particular cell, like Number column in mygrid, jqgrid is simply wrapping the content to 15+ lines on applying above CSS for wrap text , which i just need to adjust into 5 lines and not more than that.

How to adjust jqgrid cell data into 5 lines irrespective of input data length?

I tried truncating the characters where i am loosing the data.

I also tried loading limited data onload and onediting the row showing the complete data - But it is not helpful as my grid is readonly all the time.

Actually Onload we can show cell data with only 5 lines and ....... and on clicking can we expand the data? HOwever it should not cross 5 lines with atlease 6 words in each line of cell ..

I tried 'text-overflow: ellipsis' in CSS, however it is limiting the data characters and not 5 lines...

Can anyone help me in how to limit the jqgrid cell data to 5 lines?

And also width should be justified for all the columns dynamically to the max width 100% without any empty gap..

If i use above CSS i also see some extra gap at the end of the grid..

please help..!!!

Used this fork for dynamically adjusting column width... and my jqgrid version is 4.4.1

user1660325
  • 747
  • 4
  • 20
  • 35
  • Do you tried to use `max-height`? See [the old answer](http://stackoverflow.com/a/6574194/315935) as an example? Please don't post such dirty code. It used `addRowData` in the loop to fill the grid instead of using just `data: mydata, gridview: true` parameters. You use `sorttype: "date"` and `sorttype: "float"` in `colModel` for the data like `"DSK1"` and `"OPEN"`, you use `width: null` which is wrong and you mix HTML, JavaScript and CSS together. It's really not good. – Oleg Jul 30 '15 at 18:02
  • Sorry, but I don't understand what you mean. Old jqGrid have **fixed column width** specified in `colModel`. You wrote that you want that "the grid row width should be adjusted", but the row have no "width". It's either the width of the grid or the width of the column. Moreover you still write about 5 to 6 lines. The width can be specified by pixel, but not by lines. You don't wrote **which fork of jqGrid and in which version you use**. – Oleg Jul 31 '15 at 06:35
  • If you need adjust *column width dynamically* then you should use [free jqGrid](https://github.com/free-jqgrid/jqGrid) which have [the feature](https://github.com/free-jqgrid/jqGrid/wiki/Auto-adjustment-of-the-width-of-column). Free jqGrid is the fork of jqGrid which I develop. – Oleg Jul 31 '15 at 06:36
  • I wrote you already how to restrict maximal width of the row. You write about "character length check", but it can't work in common case, because the width of every character can be different and all depend from the used font and from the font size. – Oleg Jul 31 '15 at 07:24
  • I can't understand your latest comment. If you would change the `max-height` value in my demo to `max-height: 63px` you will see up to 5 lines of the text in case of using all the same fonts. – Oleg Jul 31 '15 at 07:30

0 Answers0