修复复杂表头的表格表头和字段列错位的问题
This commit is contained in:
		
							parent
							
								
									ff70a461fb
								
							
						
					
					
						commit
						af4ab7f93a
					
				| @ -394,39 +394,47 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){ | ||||
|      | ||||
|     if(type === 'width') return options.clientWidth; | ||||
| 
 | ||||
|     //初始化列参数
 | ||||
|     layui.each(options.cols, function(i1, item1){ | ||||
|       layui.each(item1, function(i2, item2){ | ||||
|         item2.colspan = item2.colspan || 1; | ||||
|         item2.rowspan = item2.rowspan || 1; | ||||
| 
 | ||||
|     // 封装对col的配置处理
 | ||||
|     var initChildCols = function (i1, item1, i2, item2) { | ||||
|       //如果列参数为空,则移除
 | ||||
|         if(!item2){ | ||||
|       if (!item2) { | ||||
|         item1.splice(i2, 1); | ||||
|         return; | ||||
|       } | ||||
| 
 | ||||
|       item2.key = i1 + '-' + i2; | ||||
|       item2.hide = item2.hide || false; | ||||
| 
 | ||||
|         //设置列的父列索引
 | ||||
|         //如果是组合列,则捕获对应的子列
 | ||||
|         if(item2.colGroup || item2.colspan > 1){ | ||||
|           var childIndex = 0; | ||||
|           layui.each(options.cols[i1 + item2.rowspan], function(i22, item22){ | ||||
|             //如果子列已经被标注为{HAS_PARENT},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
 | ||||
|             if(item22.HAS_PARENT || (childIndex >= 1 && childIndex == item2.colspan)) return; | ||||
| 
 | ||||
|             item22.HAS_PARENT = true; | ||||
|             item22.parentKey = i1 + '-' + i2; | ||||
| 
 | ||||
|             childIndex = childIndex + parseInt(item22.colspan > 1 ? item22.colspan : 1); | ||||
|           }); | ||||
|           item2.colGroup = true; //标注是组合列
 | ||||
|         } | ||||
|       item2.colspan = item2.colspan || 1; | ||||
|       item2.rowspan = item2.rowspan || 1; | ||||
| 
 | ||||
|       //根据列类型,定制化参数
 | ||||
|       that.initOpts(item2); | ||||
| 
 | ||||
|       //设置列的父列索引
 | ||||
|       //如果是组合列,则捕获对应的子列
 | ||||
|       var indexChild = i1 + (parseInt(item2.rowspan) || 1); | ||||
|       if (indexChild < options.cols.length) { // 只要不是最后一层都会有子列
 | ||||
|         item2.colGroup = true; | ||||
|         var childIndex = 0; | ||||
|         layui.each(options.cols[indexChild], function (i22, item22) { | ||||
|           //如果子列已经被标注为{HAS_PARENT},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
 | ||||
|           if (item22.HAS_PARENT || (childIndex >= 1 && childIndex == (item2.colspan || 1))) return; | ||||
| 
 | ||||
|           item22.HAS_PARENT = true; | ||||
|           item22.parentKey = i1 + '-' + i2; | ||||
|           childIndex = childIndex + parseInt(item22.colspan > 1 ? item22.colspan : 1); | ||||
|           initChildCols(indexChild, options.cols[indexChild], i22, item22); | ||||
|         }); | ||||
|       } else { | ||||
|         item2.colGroup = false; | ||||
|       } | ||||
|     }; | ||||
| 
 | ||||
|     //初始化列参数
 | ||||
|     layui.each(options.cols, function(i1, item1){ | ||||
|       if (i1) return true; | ||||
|       layui.each(item1, function(i2, item2){ | ||||
|         initChildCols(i1, item1, i2, item2); | ||||
|       }); | ||||
|     }); | ||||
|      | ||||
| @ -1888,6 +1896,26 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){ | ||||
|   thisTable.that = {}; //记录所有实例对象
 | ||||
|   thisTable.config = {}; //记录所有实例配置项
 | ||||
| 
 | ||||
|   var eachChildCols = function (index, cols, i1, item2) { | ||||
|     //如果是组合列,则捕获对应的子列
 | ||||
|     if (item2.colGroup) { | ||||
|       var childIndex = 0; | ||||
|       index++; | ||||
|       item2.CHILD_COLS = []; | ||||
|       // 找到它的子列所在cols的下标
 | ||||
|       var i2 = i1 + (parseInt(item2.rowspan) || 1); | ||||
|       layui.each(cols[i2], function (i22, item22) { | ||||
|         //如果子列已经被标注为{PARENT_COL_INDEX},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
 | ||||
|         if (item22.PARENT_COL_INDEX || (childIndex >= 1 && childIndex == (item2.colspan || 1))) return; | ||||
|         item22.PARENT_COL_INDEX = index; | ||||
| 
 | ||||
|         item2.CHILD_COLS.push(item22); | ||||
|         childIndex = childIndex + parseInt(item22.colspan > 1 ? item22.colspan : 1); | ||||
|         eachChildCols(index, cols, i2, item22); | ||||
|       }); | ||||
|     } | ||||
|   }; | ||||
| 
 | ||||
|   //遍历表头
 | ||||
|   table.eachCols = function(id, callback, cols){ | ||||
|     var config = thisTable.config[id] || {} | ||||
| @ -1897,25 +1925,9 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){ | ||||
| 
 | ||||
|     //重新整理表头结构
 | ||||
|     layui.each(cols, function(i1, item1){ | ||||
|       if (i1) return true; // 只需遍历第一层
 | ||||
|       layui.each(item1, function(i2, item2){ | ||||
|          | ||||
|         //如果是组合列,则捕获对应的子列
 | ||||
|         if(item2.colGroup){ | ||||
|           var childIndex = 0; | ||||
|           index++ | ||||
|           item2.CHILD_COLS = []; | ||||
| 
 | ||||
|           layui.each(cols[i1 + item2.rowspan], function(i22, item22){ | ||||
|             //如果子列已经被标注为{PARENT_COL_INDEX},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
 | ||||
|             if(item22.PARENT_COL_INDEX || (childIndex >= 1 && childIndex == item2.colspan)) return; | ||||
| 
 | ||||
|             item22.PARENT_COL_INDEX = index; | ||||
|              | ||||
|             item2.CHILD_COLS.push(item22); | ||||
|             childIndex = childIndex + parseInt(item22.colspan > 1 ? item22.colspan : 1); | ||||
|           }); | ||||
|         } | ||||
|          | ||||
|         eachChildCols(index, cols, i1, item2); | ||||
|         if(item2.PARENT_COL_INDEX) return; //如果是子列,则不进行追加,因为已经存储在父列中
 | ||||
|         arrs.push(item2) | ||||
|       }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user