【发布时间】:2015-10-19 05:15:24
【问题描述】:
我的网格如下,
<table id="grid"></table>
var data = [[48803, "DSK1", "", "02200220", "OPEN"], [48769, "APPR", "", "7773333777733337777333377773333777733337777333377773333777733337777333377773333777733337", "ENTERED"]];
$("#grid").jqGrid({
datatype: "local",
height: 250,
colNames: ['Inv No', 'Thingy', 'Blank', 'Number', 'Status'],
colModel: [{
name: 'id',
index: 'id',
width: 60,
sorttype: "int"},
{
name: 'thingy',
index: 'thingy',
width: 90,
sorttype: "date"},
{
name: 'blank',
index: 'blank',
width: 30},
{
name: 'number',
index: 'number',
width: 80,
sorttype: "float"},
{
name: 'status',
index: 'status',
width: 80,
sorttype: "float"}
],
caption: "Stack Overflow Example",
// ondblClickRow: function(rowid,iRow,iCol,e){alert('double clicked');}
});
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]);
}
$("#grid").on("jqGridAfterLoadComplete jqGridRemapColumns", function () {
var $this = $("#grid"),
$cells = $this.find(">tbody>tr>td"),
$colHeaders = $this.closest(".ui-jqgrid-view").find(">.ui-jqgrid-hdiv>.ui-jqgrid-hbox>.ui-jqgrid-htable>thead>.ui-jqgrid-labels>.ui-th-column>div"),
colModel = $this.jqGrid("getGridParam", "colModel"),
iCol,
iRow,
rows,
row,
n = $.isArray(colModel) ? colModel.length : 0,
cm,
colWidth,
idColHeadPrexif = "jqgh_" + this.id + "_";
$cells.wrapInner("<span class='mywrapping'></span>");
$colHeaders.wrapInner("<span class='mywrapping'></span>");
for (iCol = 0; iCol < n; iCol++) {
cm = colModel[iCol];
if (cm.hidden) {
continue;
}
colWidth = $("#" + idColHeadPrexif + $.jgrid.jqID(cm.name) + ">.mywrapping").outerWidth() + 25; // 25px for sorting icons
for (iRow = 0, rows = this.rows; iRow < rows.length; iRow++) {
row = rows[iRow];
if ($(row).hasClass("jqgrow")) {
colWidth = Math.max(colWidth, $(row.cells[iCol]).find(".mywrapping").outerWidth());
}
}
//$("#grid").jqGrid("setColWidth", iCol, colWidth);
alert(iCol + colWidth);
//$("#grid").jqGrid('setColProp',iCol,{width:colWidth});
$('#grid tr').find('td:eq('+iCol+')').each(function(){$(this).css('width',colWidth);}); // will set the column widths
//var gw = $("#grid").jqGrid('getGridParam','width');
//$("#grid").jqGrid('setGridWidth',gw);
}
});
<style type="text/css">
.ui-jqgrid tr.jqgrow td {
word-wrap: break-word; /* IE 5.5+ and CSS3 */
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
overflow: hidden;
height: auto;
vertical-align: middle;
padding-top: 3px;
padding-bottom: 3px
}
</style>
我正在尝试使用 , 为列设置自动宽度
$("#grid").jqGrid("setColWidth", iCol, colWidth);
这导致我“setColWidth 未定义”。顺便说一句,我正在使用 jquery1.8。
然后我尝试使用这种方式,
$('#grid tr').find('td:eq('+iCol+')').each(function(){$(this).css('width',colWidth);});
这并没有给出任何脚本错误,但它也没有设置列的宽度。
但是当我这样做时,每列的宽度都被正确打印了,
alert(iCol + colWidth);
我在这段代码中做错了什么?有谁能帮我解决这个问题?
我该如何解决这个问题...?
需要帮助...
在此先感谢...
【问题讨论】:
-
您使用哪个 jqGrid 的分支(版本 free jqGrid 或 Guriddo jqGrid JS 中的旧 jqGrid)以及使用哪个版本?
-
@Oleg 我在这里面临的挑战是 1)这个数据 77733337777777333377773333777733337777333377773333777733337777333377773337 必须是自动换行最多 10 行以上...你能帮忙吗?
-
@Oleg :我正在使用 jqGrid 4.4.1 - jQuery ..
标签: javascript jquery html css jqgrid