【发布时间】:2013-10-04 10:35:25
【问题描述】:
我有一个 jqGrid 表的问题,我无法找到解决方案,也无法找到引导我正确方向的答案,我已经阅读了一些答案,但没有一个专注于我的问题:
- JQGrid data not being displayed
- jqgrid fail to display json data
- jqGrid fetched json but has empty rows and no data
- JqGrid is not able to display data
- JQGrid not showing json data
到目前为止,我阅读的许多相关问题都集中在使用 JSON 数据填充网格,但我的情况并非如此。我填充网格的方式是使用addRowData 方法,它似乎有效,因为当我在浏览器的调试工具(Chrome 29.0.1547.76 m)和table、tbody 上检查表格元素时加上所有 tr 元素与预期数据一起存在,但它们不可见!
所有行的宽度和高度都为 0px,这就是为什么(我想)数据不显示的原因。但是我用同样的方法显示另一个表,结果是可见的。
我无法粘贴所有代码,因为它很乱而且很乱,但我会尽力提供有用的信息:
// The ConvertTojqGrid method converts the data (array object)
// into the format expected by jqGrid in order to provide the
// colModel and rows
var jqGridData = ConvertTojqGrid(data);
// the divID begins with '#'
var div = jQuery(divID)[0];
var table = divID + '_table'
jQuery(divID).append('<table id="' + table.substr(1) + '"></table>');
// get rid of the '#' in the string ^^^^^^^^^^^^^^^
jQuery(table).jqGrid(
{
autowidth: true,
gridview: true,
headertitles: true,
datatype: 'clientSide',
caption: gridCaption,
colModel: jqGridData.colModel,
records: jqGridData.rows.length,
height: div.clientHeight,
width: div.clientWidth
});
jqGridData.rows.forEach(function(row)
{
jQuery(table).addRowData('row_id', row);
});
网页显示了一个表格,其中包含按预期显示的数据但隐藏了一些列,在表格的左上方放置了一个按钮,该按钮显示了一个带有另一个网格的表格,该表格显示了没有隐藏列的同一个表格。
所有表格都放入运行时生成的div 中,并在此div 中生成table 标记以包含网格。
简而言之,问题不在于获取数据,也不在于填表,问题在于数据正确,填表但行不可见。
任何建议都会受到欢迎。
【问题讨论】:
标签: javascript jquery jqgrid