jggrid 合并单元格
jQuery().ready(function (){ jQuery("#list").jqGrid({ url:'url', datatype: "xml", colNames:['调研记录单编号','申请科室','设备名称','批准数量','批准金额','资金来源','招标类型','品牌','供应商','规格','型号'], colModel:[ {name:'Bill_No',index:'Bill_No', width:130, align:'center', sortable:true}, {name:'deptName',index:'deptName', width:100, align:'center', sortable:true}, {name:'productName',index:'productName', width:100, align:'center', sortable:true}, {name:'qty',index:'qty', width:80, align:'center', sortable:true}, {name:'money',index:'money', width:80, align:'center', sortable:true}, {name:'source',index:'source', width:80, align:'center', sortable:true}, {name:'type',index:'type', width:80, align:'center', sortable:false}, {name:'brand',index:'brand', width:80, align:'center', sortable:false}, {name:'supplier',index:'supplier', width:80, align:'center', sortable:false}, {name:'spec',index:'spec', width:80, align:'center', sortable:false}, {name:'number',index:'number', width:80, align:'center', sortable:false} ], // rowNum:20, autowidth: false, // rowList:[20,30,50], pager: jQuery('#pager'), sortname: 'id', viewrecords: true, sortorder: "desc", height: 'auto', multiselect: false, afterInsertRow: function(rowId, rowData){ var order='<a href=\'#\'><div style="text-decoration : underline;color:#3366FF" onclick="doView(\'' +rowData['surveyId']+ '\')">'+rowData['Bill_No']+'</div></a>'; $("#list").setRowData(rowId,{Bill_No:order}); }, beforeRequest:function(){}, loadComplete:function(){ merge_rowspan("#list",1,8); } });
//合并行(单元格中的数据相同的合并) //函数说明:合并指定表格(表格id为_w_table_id)指定行(行数为_w_table_rownum)的相同文本的相邻单元格 //参数说明:_w_table_id 为需要进行合并单元格的表格id。如在HTMl中指定表格 id="data" ,此参数应为 #data //参数说明:_w_table_colnum 为需要合并单元格的所在列。为数字,从最左边第一列为1开始算起。 //参数说明:col_num 需要合并的列数。为数字,从最左边第一列为1开始算起。 function merge_rowspan(_w_table_id,_w_table_colnum,col_num){ _w_table_firsttd = ""; _w_table_currenttd = ""; _w_table_SpanNum = 0; _w_table_Obj = $(_w_table_id + " tr td:nth-child(" + _w_table_colnum + ")"); _w_table_Obj.each(function(i){ if(i==0){ _w_table_firsttd = $(this); _w_table_SpanNum = 1; }else{ _w_table_currenttd = $(this); if(_w_table_firsttd.text()==_w_table_currenttd.text()){ _w_table_SpanNum++; for(var j=0;j<col_num;j+=1){ _w_table_firsttd.parent().find("td:eq("+j+")").attr("rowSpan",_w_table_SpanNum); _w_table_currenttd.parent().find("td:eq("+j+")").hide(); } }else{ _w_table_firsttd = $(this); _w_table_SpanNum = 1; } } }); }