欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

easyUI 合并单元格

程序员文章站 2024-02-28 19:08:16
...

<script type="text/javascript" src="${base}/js/deyi-util.js"></script>

在页面中引用  deyi-util.js 。

deyi-util.js :

deyisys.util = {
    tableMerges : function (id, fieldArr) {
		for ( var i = 0; i < fieldArr.length; i++) {
			deyisys.util.tableMerge(id, fieldArr[i]);
		}
	},
    tableMerge : function (id, field) {
		var tabId = '#' + id;
		var rows = $(tabId).datagrid('getRows');
		var len = rows.length;
		var rowStr = "";
		var merges = [];
		var j = 0;
		var x = 0;
		for ( var i = 0; i < rows.length; i++) {
			var row = rows[i];
			if (i == 0) {
				rowStr = row[field];
				var merObj = {};
				merObj.index = 0;
				merges[j] = merObj;
			}
			if (rowStr != row[field]) {
				rowStr = row[field];
				merges[j].rowspan = x;
				x = 1;
				j++;
				var merObj = {};
				merObj.index = i;
				merges[j] = merObj;
			} else {
				x++;
			}
			if (i == (rows.length - 1)) {
				merges[j].rowspan = x;
			}
		}
		for ( var i = 0; i < merges.length; i++) {
			$(tabId).datagrid('mergeCells', {
				index : merges[i].index,
				field : field,
				rowspan : merges[i].rowspan
			});
		}
	},
}

jsp 页面:

onLoadSuccess:function(data){
      	/**页面合并行用*/
        deyisys.util.tableMerges('diseaseGeneList',['diseaseName','subjectName','omim']);
      },

diseaseGeneList:页面table 的Id,['diseaseName','subjectName','omim'] 是要根据哪些列进行合并

相关标签: a