mirror of https://github.com/layui/layui
table: [修复] 合计行自定义模板后,未优先读取后端返回的合计数据的问题
parent
90d1542205
commit
7ae590daec
|
@ -163,7 +163,7 @@ layui.use(['table', 'dropdown'], function(){
|
||||||
return td.find('select').val();
|
return td.find('select').val();
|
||||||
}}
|
}}
|
||||||
,{field:'sign', title:'签名', minWidth: 200, style:'color: #5FB878', edit: 'textarea'}
|
,{field:'sign', title:'签名', minWidth: 200, style:'color: #5FB878', edit: 'textarea'}
|
||||||
,{field: 'experience', title: '积分', width: 100, sort: true, align:'center', totalRow: !1 ? '{{=d.LAY_COL.field}}' : '{{= d.TOTAL_NUMS }} 分 😊', templet: '<div><a href="" class="layui-table-link">{{ d.experience }}</a> 分</div>'}
|
,{field: 'experience', title: '积分', width: 100, sort: true, align:'center', totalRow: !1 ? true : '{{= d.TOTAL_NUMS }} 分 😊', templet: '<div><a href="" class="layui-table-link">{{= d[d.LAY_COL.field] }}</a> 分</div>'}
|
||||||
,{field:'ip', title:'IP', width: 120, align: 'right'}
|
,{field:'ip', title:'IP', width: 120, align: 'right'}
|
||||||
,{field:'checkin', title:'打卡', width: 100, sort: true, totalRow: '{{= parseInt(d.TOTAL_NUMS) }} 次'}
|
,{field:'checkin', title:'打卡', width: 100, sort: true, totalRow: '{{= parseInt(d.TOTAL_NUMS) }} 次'}
|
||||||
,{field:'joinTime', title:'加入时间', width: 120}
|
,{field:'joinTime', title:'加入时间', width: 120}
|
||||||
|
@ -405,7 +405,7 @@ layui.use(['table', 'dropdown'], function(){
|
||||||
}, function(value, index){
|
}, function(value, index){
|
||||||
obj.update({
|
obj.update({
|
||||||
email: value
|
email: value
|
||||||
});
|
}, true);
|
||||||
/*
|
/*
|
||||||
// 上述 obj.update() 只是在前端临时更新数据视图
|
// 上述 obj.update() 只是在前端临时更新数据视图
|
||||||
// 在实际业务中,当发送修改请求成功后,可再执行 reloadData 来重载数据
|
// 在实际业务中,当发送修改请求成功后,可再执行 reloadData 来重载数据
|
||||||
|
@ -448,7 +448,7 @@ layui.use(['table', 'dropdown'], function(){
|
||||||
|
|
||||||
var update = {};
|
var update = {};
|
||||||
update[field] = value;
|
update[field] = value;
|
||||||
obj.update(update);
|
obj.update(update, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -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){
|
||||||
|
@ -1171,56 +1171,60 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
var tds = [];
|
var tds = [];
|
||||||
that.eachCols(function(i3, item3){
|
that.eachCols(function(i3, item3){
|
||||||
var field = item3.field || i3;
|
var field = item3.field || i3;
|
||||||
|
|
||||||
|
// 合计数据的特定字段
|
||||||
|
var TOTAL_NUMS = totalRowData && totalRowData[item3.field];
|
||||||
|
|
||||||
//td 内容
|
// 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;
|
||||||
|
|
Loading…
Reference in New Issue