|
|
@ -1144,16 +1144,16 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//数据合计行
|
|
|
|
// 数据合计行
|
|
|
|
Class.prototype.renderTotal = function(data, totalRowData){ |
|
|
|
Class.prototype.renderTotal = function(data, totalRowData){ |
|
|
|
var that = this |
|
|
|
var that = this; |
|
|
|
,options = that.config |
|
|
|
var options = that.config; |
|
|
|
,totalNums = {}; |
|
|
|
var totalNums = {}; |
|
|
|
|
|
|
|
|
|
|
|
if(!options.totalRow) return; |
|
|
|
if(!options.totalRow) return; |
|
|
|
|
|
|
|
|
|
|
|
layui.each(data, function(i1, item1){ |
|
|
|
layui.each(data, function(i1, item1){ |
|
|
|
//若数据项为空数组,则不往下执行(因为删除数据时,会将原有数据设置为 [])
|
|
|
|
// 若数据项为空数组,则不往下执行(因为删除数据时,会将原有数据设置为 [])
|
|
|
|
if(layui.type(item1) === 'array' && item1.length === 0) return; |
|
|
|
if(layui.type(item1) === 'array' && item1.length === 0) return; |
|
|
|
|
|
|
|
|
|
|
|
that.eachCols(function(i3, item3){ |
|
|
|
that.eachCols(function(i3, item3){ |
|
|
@ -1172,55 +1172,59 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ |
|
|
|
that.eachCols(function(i3, item3){ |
|
|
|
that.eachCols(function(i3, item3){ |
|
|
|
var field = item3.field || i3; |
|
|
|
var field = item3.field || i3; |
|
|
|
|
|
|
|
|
|
|
|
//td 内容
|
|
|
|
// 合计数据的特定字段
|
|
|
|
|
|
|
|
var TOTAL_NUMS = totalRowData && totalRowData[item3.field]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// td 内容
|
|
|
|
var content = function(){ |
|
|
|
var content = function(){ |
|
|
|
var text = item3.totalRowText || '' |
|
|
|
var text = item3.totalRowText || ''; |
|
|
|
,decimals = 'totalRowDecimals' in item3 ? item3.totalRowDecimals : 2 |
|
|
|
var decimals = 'totalRowDecimals' in item3 ? item3.totalRowDecimals : 2; |
|
|
|
,thisTotalNum = parseFloat(totalNums[field]).toFixed(decimals) |
|
|
|
var thisTotalNum = parseFloat(totalNums[field]).toFixed(decimals); |
|
|
|
,tplData = { |
|
|
|
var tplData = { |
|
|
|
LAY_COL: item3 |
|
|
|
LAY_COL: item3 |
|
|
|
} |
|
|
|
}; |
|
|
|
,getContent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tplData[field] = thisTotalNum; |
|
|
|
tplData[field] = thisTotalNum; |
|
|
|
|
|
|
|
|
|
|
|
//获取自动计算的合并内容
|
|
|
|
// 获取自动计算的合并内容
|
|
|
|
getContent = item3.totalRow ? (parseTempData.call(that, { |
|
|
|
var getContent = item3.totalRow ? (parseTempData.call(that, { |
|
|
|
item3: item3 |
|
|
|
item3: item3 |
|
|
|
,content: thisTotalNum |
|
|
|
,content: thisTotalNum |
|
|
|
,tplData: tplData |
|
|
|
,tplData: tplData |
|
|
|
}) || text) : text; |
|
|
|
}) || text) : text; |
|
|
|
|
|
|
|
|
|
|
|
//如果直接传入了合计行数据,则不输出自动计算的结果
|
|
|
|
// 如果直接传入了合计行数据,则不输出自动计算的结果
|
|
|
|
return totalRowData ? (totalRowData[item3.field] || getContent) : getContent; |
|
|
|
return TOTAL_NUMS || getContent; |
|
|
|
}() |
|
|
|
}(); |
|
|
|
,td = ['<td data-field="'+ field +'" data-key="'+ options.index + '-'+ item3.key +'" '+ function(){ |
|
|
|
|
|
|
|
|
|
|
|
// td 容器
|
|
|
|
|
|
|
|
var td = ['<td data-field="'+ field +'" data-key="'+ options.index + '-'+ item3.key +'" '+ function(){ |
|
|
|
var attr = []; |
|
|
|
var attr = []; |
|
|
|
if(item3.align) attr.push('align="'+ item3.align +'"'); //对齐方式
|
|
|
|
if(item3.align) attr.push('align="'+ item3.align +'"'); // 对齐方式
|
|
|
|
if(item3.minWidth) attr.push('data-minwidth="'+ item3.minWidth +'"'); //单元格最小宽度
|
|
|
|
if(item3.minWidth) attr.push('data-minwidth="'+ item3.minWidth +'"'); // 单元格最小宽度
|
|
|
|
return attr.join(' '); |
|
|
|
return attr.join(' '); |
|
|
|
}() +' class="'+ function(){ //追加样式
|
|
|
|
}() +' class="'+ function(){ // 追加样式
|
|
|
|
var classNames = []; |
|
|
|
var classNames = []; |
|
|
|
if(item3.hide) classNames.push(HIDE); //插入隐藏列样式
|
|
|
|
if(item3.hide) classNames.push(HIDE); // 插入隐藏列样式
|
|
|
|
if(!item3.field) classNames.push(ELEM_COL_SPECIAL); //插入特殊列样式
|
|
|
|
if(!item3.field) classNames.push(ELEM_COL_SPECIAL); // 插入特殊列样式
|
|
|
|
return classNames.join(' '); |
|
|
|
return classNames.join(' '); |
|
|
|
}() +'">' |
|
|
|
}() +'">' |
|
|
|
,'<div class="layui-table-cell laytable-cell-'+ function(){ //返回对应的CSS类标识
|
|
|
|
,'<div class="layui-table-cell laytable-cell-'+ function(){ // 返回对应的CSS类标识
|
|
|
|
var str = (options.index + '-' + item3.key); |
|
|
|
var str = (options.index + '-' + item3.key); |
|
|
|
return item3.type === 'normal' ? str
|
|
|
|
return item3.type === 'normal' ? str
|
|
|
|
: (str + ' laytable-cell-' + item3.type); |
|
|
|
: (str + ' laytable-cell-' + item3.type); |
|
|
|
}() +'"'+ function(){ |
|
|
|
}() +'"'+ function(){ |
|
|
|
var attr = []; |
|
|
|
var attr = []; |
|
|
|
if(item3.style) attr.push('style="'+ item3.style +'"'); //自定义单元格样式
|
|
|
|
if(item3.style) attr.push('style="'+ item3.style +'"'); // 自定义单元格样式
|
|
|
|
return attr.join(' '); |
|
|
|
return attr.join(' '); |
|
|
|
}() +'>' + function(){ |
|
|
|
}() +'>' + function(){ |
|
|
|
var totalRow = item3.totalRow || options.totalRow; |
|
|
|
var totalRow = item3.totalRow || options.totalRow; |
|
|
|
|
|
|
|
|
|
|
|
//如果 totalRow 参数为字符类型,则解析为自定义模版
|
|
|
|
// 如果 totalRow 参数为字符类型,则解析为自定义模版
|
|
|
|
if(typeof totalRow === 'string'){ |
|
|
|
if(typeof totalRow === 'string'){ |
|
|
|
return laytpl(totalRow).render($.extend({ |
|
|
|
return laytpl(totalRow).render($.extend({ |
|
|
|
TOTAL_NUMS: totalNums[field] |
|
|
|
TOTAL_NUMS: TOTAL_NUMS || totalNums[field], |
|
|
|
,LAY_COL: item3 |
|
|
|
LAY_COL: item3 |
|
|
|
}, item3)); |
|
|
|
}, item3)); |
|
|
|
} |
|
|
|
} |
|
|
|
return content; |
|
|
|
return content; |
|
|
|