easyui datagrid合并单元格算法 复杂度为o(1) NB

<script type="text/javascript">
var datagrid;
	$(function() {
		
     $('#abdg').datagrid(
						{
							url : "${pageContext.request.contextPath}/diaryController/diaryException",
							toolbar : "#tool",
							border : true,
							pagination : true,
							singleSelect : true,
					        rownumbers:true,
							pageSize : 10,
							pageList : [ 10, 20 ],
							fit:true,
							sortName : 'day',
							sortOrder : 'desc',
							onLoadSuccess:onLoadSuccess,
							onBeforeLoad:function onBeforeLoad(){
								parent.$.messager.progress({
									title : '提示',
									text : '正在奋力统计中....'
								});
							},
							columns : [ [
							 {
								field : 'member',
								title : '人员',
								width : 100,
							}, {
								field : 'day',
								title : '日志日期',
								width : 80,
							}, {
								field : 'createdate',
								title : '创建日期',
								width : 100,
						   },{
								field : 'exceptionState',
								title : '异常状态',
								width : 80,
								formatter:function(value,row,index){
									if(row.day>row.createdate){
										return '<font color=blue>提前</font>';
									}
									if(row.day<row.createdate){
										return '<font color=purple>滞后</font>';
									}
										return '<font color=red>'+value+'</font>';
								}
							}
						   ,{
								field : 'exceptionHit',
								title : '异常次数',
								width : 80,
								formatter:function(value,row,index){
									return "异常<font color=red>"+value+'</font>次';
									
								}
							}
						   ]],
						});
	
	});
	
	//合并单元格
	function onLoadSuccess(data){
		var array=new Array();
		var rows=data.rows;
		var b=0;
	    for(var i=0; i<rows.length; i++){
	    	var a=1;
	    for(var j=i+1;j<rows.length;j++){
	     if(i!=j){
	    	 if(rows[i].member==rows[j].member)
	    		 {
	    		 a++;
	    		 i++;
	    		 array[b]={     
		    			 index: i-a+1,
		                 rowspan: a
		                 };
	    	     b++;
	    		 }
	     }
	
	     }
	
	    }
	     for(var i=0; i<array.length; i++){
             $(this).datagrid('mergeCells',{
                 index: array[i].index,
                 field: 'member',
                 rowspan: array[i].rowspan
             });
             $(this).datagrid('mergeCells',{
                 index: array[i].index,
                 field: 'exceptionHit',
                 rowspan: array[i].rowspan
             });
         }
	     parent.$.messager.progress('close');
	}
	function searchFun() {
		$('#abdg').datagrid('load', $.serializeObject($('#sear')));
	}
</script>
点赞