jqGrid中获取subGrid的标题栏对象
jqGrid中subGrid的使用方法也很简单,设置subGrid:true,并且配置subGridRowExpanded,该属性是一个函数,在这个函数实现对subGrid的绘制,
思路也很简单,就是在当前的格子中插入table和div,然后在是通常的jqGrid的写法。大多数参数的配置和jqGrid的常规配置一致。
在要获取标题栏的时候,通过打印html(),发现,jqGrid构造的表格还是很复杂的。它的标题栏不是想象中的首行,而是另外一个独立的table,因此,要获得它也蛮复杂的,通过一系列parent()方法。下面是一段例子
subGridRowExpanded: function(subgrid_id, row_id) {
// we pass two parameters
// subgrid_id is a id of the div tag created within a table
// the row_id is the id of the row
// If we want to pass additional parameters to the url we can use
// the method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the following
var subgrid_table_id,subgrid_pager_id;
subgrid_table_id = subgrid_id+"_t";
subgrid_pager_id = subgrid_id+"_div";
jQuery("#"+subgrid_id).append("
");
jQuery("#"+subgrid_id).append("
");
jQuery("#"+subgrid_table_id).jqGrid({
url:"./AjaxHandler/jqGrid_Jsondata_Content.ashx?id="+row_id,
datatype: "json",
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "rowid"
},
colNames: ["内容", "作者", "时间"],
colModel: [
{ name: "content", index: "content", 550, sorttype: "string",sortable:false },
{ name: "author", index: "author", 80, sorttype: "string", formatter: "string",sortable:false },
{ name: "datetime", index: "datetime", 80, sorttype: "string", formatter: "string",sortable:false}
],
rowNum: 15,
height: "100%",
viewrecords: true,
pager:"#"+subgrid_pager_id,
loadComplete:function(){
//隐藏第一行标题栏
var p= $("#"+subgrid_table_id).parent().parent().parent()
p=$(p).find("table").first().hide();
}
   });
}
表格html如下:
< TABLE style=" 725px" class=ui-jqgrid-htable role=grid aria-labelledby=gbox_listdata_jqtr88_t border=0 cellSpacing=0 cellPadding=0>
 
内容
 
作者
 
时间
TABLE >
< TABLE style=" 725px" id=listdata_jqtr88_t class="  ui-jqgrid-btable" role=grid tabIndex=1 aria-labelledby=gbox_listdata_jqtr88_t aria-multiselectable=false border=0 cellSpacing=0 cellPadding=0>
TABLE >