From 7ae590daecb6180a32c8707fa5bbf761548a172f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sat, 9 Jul 2022 19:06:59 +0800 Subject: [PATCH] =?UTF-8?q?table:=20[=E4=BF=AE=E5=A4=8D]=20=E5=90=88?= =?UTF-8?q?=E8=AE=A1=E8=A1=8C=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E6=9C=AA=E4=BC=98=E5=85=88=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E8=BF=94=E5=9B=9E=E7=9A=84=E5=90=88=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/table-test.html | 6 ++-- src/modules/table.js | 60 +++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/examples/table-test.html b/examples/table-test.html index 9cf2342a..dd5571d4 100644 --- a/examples/table-test.html +++ b/examples/table-test.html @@ -163,7 +163,7 @@ layui.use(['table', 'dropdown'], function(){ return td.find('select').val(); }} ,{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: '
'} + ,{field: 'experience', title: '积分', width: 100, sort: true, align:'center', totalRow: !1 ? true : '{{= d.TOTAL_NUMS }} 分 😊', templet: ''} ,{field:'ip', title:'IP', width: 120, align: 'right'} ,{field:'checkin', title:'打卡', width: 100, sort: true, totalRow: '{{= parseInt(d.TOTAL_NUMS) }} 次'} ,{field:'joinTime', title:'加入时间', width: 120} @@ -405,7 +405,7 @@ layui.use(['table', 'dropdown'], function(){ }, function(value, index){ obj.update({ email: value - }); + }, true); /* // 上述 obj.update() 只是在前端临时更新数据视图 // 在实际业务中,当发送修改请求成功后,可再执行 reloadData 来重载数据 @@ -448,7 +448,7 @@ layui.use(['table', 'dropdown'], function(){ var update = {}; update[field] = value; - obj.update(update); + obj.update(update, true); }); }); diff --git a/src/modules/table.js b/src/modules/table.js index cf121321..660f9cde 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1144,16 +1144,16 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ } }; - //数据合计行 + // 数据合计行 Class.prototype.renderTotal = function(data, totalRowData){ - var that = this - ,options = that.config - ,totalNums = {}; + var that = this; + var options = that.config; + var totalNums = {}; if(!options.totalRow) return; layui.each(data, function(i1, item1){ - //若数据项为空数组,则不往下执行(因为删除数据时,会将原有数据设置为 []) + // 若数据项为空数组,则不往下执行(因为删除数据时,会将原有数据设置为 []) if(layui.type(item1) === 'array' && item1.length === 0) return; that.eachCols(function(i3, item3){ @@ -1171,56 +1171,60 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ var tds = []; that.eachCols(function(i3, item3){ var field = item3.field || i3; + + // 合计数据的特定字段 + var TOTAL_NUMS = totalRowData && totalRowData[item3.field]; - //td 内容 + // td 内容 var content = function(){ - var text = item3.totalRowText || '' - ,decimals = 'totalRowDecimals' in item3 ? item3.totalRowDecimals : 2 - ,thisTotalNum = parseFloat(totalNums[field]).toFixed(decimals) - ,tplData = { + var text = item3.totalRowText || ''; + var decimals = 'totalRowDecimals' in item3 ? item3.totalRowDecimals : 2; + var thisTotalNum = parseFloat(totalNums[field]).toFixed(decimals); + var tplData = { LAY_COL: item3 - } - ,getContent; + }; tplData[field] = thisTotalNum; - //获取自动计算的合并内容 - getContent = item3.totalRow ? (parseTempData.call(that, { + // 获取自动计算的合并内容 + var getContent = item3.totalRow ? (parseTempData.call(that, { item3: item3 ,content: thisTotalNum ,tplData: tplData }) || text) : text; - //如果直接传入了合计行数据,则不输出自动计算的结果 - return totalRowData ? (totalRowData[item3.field] || getContent) : getContent; - }() - ,td = ['