|
|
|
@ -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; |
|
|
|
|
item2.colspan = item2.colspan || 1; |
|
|
|
|
item2.rowspan = item2.rowspan || 1; |
|
|
|
|
|
|
|
|
|
//根据列类型,定制化参数
|
|
|
|
|
that.initOpts(item2); |
|
|
|
|
|
|
|
|
|
//设置列的父列索引
|
|
|
|
|
//如果是组合列,则捕获对应的子列
|
|
|
|
|
if(item2.colGroup || item2.colspan > 1){ |
|
|
|
|
var indexChild = i1 + (parseInt(item2.rowspan) || 1); |
|
|
|
|
if (indexChild < options.cols.length) { // 只要不是最后一层都会有子列
|
|
|
|
|
item2.colGroup = true; |
|
|
|
|
var childIndex = 0; |
|
|
|
|
layui.each(options.cols[i1 + item2.rowspan], function(i22, item22){ |
|
|
|
|
layui.each(options.cols[indexChild], function (i22, item22) { |
|
|
|
|
//如果子列已经被标注为{HAS_PARENT},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
|
|
|
|
|
if(item22.HAS_PARENT || (childIndex >= 1 && childIndex == item2.colspan)) return; |
|
|
|
|
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); |
|
|
|
|
}); |
|
|
|
|
item2.colGroup = true; //标注是组合列
|
|
|
|
|
} else { |
|
|
|
|
item2.colGroup = false; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//根据列类型,定制化参数
|
|
|
|
|
that.initOpts(item2); |
|
|
|
|
//初始化列参数
|
|
|
|
|
layui.each(options.cols, function(i1, item1){ |
|
|
|
|
if (i1) return true; |
|
|
|
|
layui.each(item1, function(i2, item2){ |
|
|
|
|
initChildCols(i1, item1, i2, item2); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -1888,34 +1896,38 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
|
|
|
|
|
thisTable.that = {}; //记录所有实例对象
|
|
|
|
|
thisTable.config = {}; //记录所有实例配置项
|
|
|
|
|
|
|
|
|
|
//遍历表头
|
|
|
|
|
table.eachCols = function(id, callback, cols){ |
|
|
|
|
var config = thisTable.config[id] || {} |
|
|
|
|
,arrs = [], index = 0; |
|
|
|
|
|
|
|
|
|
cols = $.extend(true, [], cols || config.cols); |
|
|
|
|
|
|
|
|
|
//重新整理表头结构
|
|
|
|
|
layui.each(cols, function(i1, item1){ |
|
|
|
|
layui.each(item1, function(i2, item2){ |
|
|
|
|
|
|
|
|
|
var eachChildCols = function (index, cols, i1, item2) { |
|
|
|
|
//如果是组合列,则捕获对应的子列
|
|
|
|
|
if(item2.colGroup){ |
|
|
|
|
if (item2.colGroup) { |
|
|
|
|
var childIndex = 0; |
|
|
|
|
index++ |
|
|
|
|
index++; |
|
|
|
|
item2.CHILD_COLS = []; |
|
|
|
|
|
|
|
|
|
layui.each(cols[i1 + item2.rowspan], function(i22, item22){ |
|
|
|
|
// 找到它的子列所在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)) return; |
|
|
|
|
|
|
|
|
|
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] || {} |
|
|
|
|
,arrs = [], index = 0; |
|
|
|
|
|
|
|
|
|
cols = $.extend(true, [], cols || config.cols); |
|
|
|
|
|
|
|
|
|
//重新整理表头结构
|
|
|
|
|
layui.each(cols, function(i1, item1){ |
|
|
|
|
if (i1) return true; // 只需遍历第一层
|
|
|
|
|
layui.each(item1, function(i2, item2){ |
|
|
|
|
eachChildCols(index, cols, i1, item2); |
|
|
|
|
if(item2.PARENT_COL_INDEX) return; //如果是子列,则不进行追加,因为已经存储在父列中
|
|
|
|
|
arrs.push(item2) |
|
|
|
|
}); |
|
|
|
|