From 506e6ff573c22cf58ccb7657ada03db79aa2c6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 17 Jul 2022 11:41:00 +0800 Subject: [PATCH] =?UTF-8?q?table:=20=E6=96=B0=E5=A2=9E=E3=80=81=E5=8A=A0?= =?UTF-8?q?=E5=BC=BA=E5=92=8C=E4=BF=AE=E5=A4=8D=E8=8B=A5=E5=B9=B2=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/json/table/demo1.json | 2 +- examples/table-test.html | 6 ++- examples/table.html | 21 ++++---- src/modules/table.js | 93 ++++++++++++++++++++-------------- 4 files changed, 72 insertions(+), 50 deletions(-) diff --git a/examples/json/table/demo1.json b/examples/json/table/demo1.json index b9217e85..39bee73e 100644 --- a/examples/json/table/demo1.json +++ b/examples/json/table/demo1.json @@ -9,7 +9,7 @@ "id": "10001" ,"username": "杜甫123" ,"email": "test1@email.com" - ,"sex": "男" + ,"sex": "男" ,"city": "浙江杭州" ,"sign": "舍南舍北皆春水,但见群鸥日日来。花径不曾缘客扫,蓬门今始为君开。盘飧市远无兼味,樽酒家贫只旧醅。肯与邻翁相对饮,隔篱呼取尽余杯。" ,"experience": 7 diff --git a/examples/table-test.html b/examples/table-test.html index fc7fa210..6f2498c4 100644 --- a/examples/table-test.html +++ b/examples/table-test.html @@ -152,11 +152,13 @@ layui.use(['table', 'dropdown'], function(){ {type: 'checkbox', fixed: 'left'} //,{type: 'numbers', fixed: 'left'} ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计:'} - ,{field:'username', title:'用户名', width:120, edit: 'text', templet: '#usernameTpl'} + ,{field:'username', title:'用户名', width:120, edit: function(d){ + return !d.LAY_DISABLED; + }, templet: '#usernameTpl'} ,{field:'email', minWidth: 160, title:'邮箱 ', hide: 0, edit: 'text', templet: function(d){ return ''+ layui.util.escape(d.email) +'' }} - ,{field:'sex', title:'性别', width:80, edit: 'text', sort: true} + ,{field:'sex', title:'性别', width:80, edit: 'text', sort: true, escape: false} ,{field:'city', title:'城市', width:120, templet: '#cityTpl', exportTemplet: function(d, obj){ //console.log(obj) var td = obj.td(this.field); //获取当前 td diff --git a/examples/table.html b/examples/table.html index f1ab71cc..37f655cf 100644 --- a/examples/table.html +++ b/examples/table.html @@ -228,16 +228,17 @@ layui.use('table', function(){ //,width: 900 //,height: 274 ,cols: [[ //标题栏 - {type: 'checkbox', LAY_CHECKED: true} - ,{field: 'id', title: 'ID', width: 80, sort: true} - ,{type: 'space', width: 100} //空列 - ,{field: 'username', title: '用户名', width: 120} - ,{field: 'email', title: '邮箱', width: 150} - ,{field: 'sign', title: '签名', width: 150} - ,{field: 'sex', title: '性别', width: 80} - ,{field: 'city', title: '城市', width: 100} - // ,{field: 'experience', title: '积分', width: 80, sort: true} - ,{field: 'experience', title: '积分', width: 80, sort: true, totalRow: '{{= parseInt(d.TOTAL_NUMS) }}'} + //{type: 'space'}, + {type: 'checkbox', LAY_CHECKED: true}, + {field: 'id', title: 'ID', width: 80, sort: true}, + {type: 'space', width: 100}, //空列 + {field: 'username', title: '用户名', width: 120}, + {field: 'email', title: '邮箱', width: 150}, + {field: 'sign', title: '签名', minWidth: 150}, + {field: 'sex', title: '性别', width: 80}, + {field: 'city', title: '城市', width: 100}, + //{field: 'experience', title: '积分', width: 80, sort: true}, + {field: 'experience', title: '积分', width: 80, sort: true, totalRow: '{{= parseInt(d.TOTAL_NUMS) }}'} ]] ,data: [{ "id": "10001" diff --git a/src/modules/table.js b/src/modules/table.js index 660f9cde..508d8311 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -77,12 +77,13 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ ,parseTempData = function(obj){ obj = obj || {}; - var options = this.config || {} - ,item3 = obj.item3 // 表头数据 - ,content = obj.content; // 原始内容 + var options = this.config || {}; + var item3 = obj.item3; // 表头数据 + var content = obj.content; // 原始内容 // 是否编码 HTML - if(options.escape) content = util.escape(content); + var escaped = 'escape' in item3 ? item3.escape : options.escape; + if(escaped) content = util.escape(content); // 获取模板 var templet = obj.text && item3.exportTemplet || (item3.templet || item3.toolbar); @@ -91,7 +92,9 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ if(templet){ content = typeof templet === 'function' ? templet.call(item3, obj.tplData, obj.obj) - : laytpl($(templet).html() || String(content)).render(obj.tplData); + : laytpl($(templet).html() || String(content)).render($.extend({ + LAY_COL: item3 + }, obj.tplData)); } // 是否只返回文本 @@ -430,7 +433,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ ,initWidth = { checkbox: 50 ,radio: 50 - ,space: 15 + ,space: 30 ,numbers: 60 }; @@ -918,6 +921,18 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ return that; }; + // 获取表头参数项 + Class.prototype.col = function(key){ + try { + key = key.split('-'); + return this.config.cols[key[1]][key[2]]; + } catch(e){ + hint.error(e); + return {}; + } + }; + + // 数据渲染 Class.prototype.renderData = function(opts){ var that = this; @@ -965,11 +980,10 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ if(content === undefined || content === null) content = ''; if(item3.colGroup) return; - //td内容 + // td 内容 var td = ['