layui table 表格上添加日期控件的两种方法

var tableInit = table.render({ elem: '#tbtxrz' , method: 'post' , data: jsonData , height: "auto" , id: "tbtxrz" , text: {none: '暂无相关数据'} , toolbar: toolbartxrz , cols: [[ { //设置表格中部分字体的颜色 field: "number", title: "序号", width: 60, align: "left", templet: function (data) { return data.LAY_INDEX } } , {field: "ID", title: "ID", align: "left", hide: true} , {field: "sjbs", title: "sjbs", align: "left", hide: true} , {field: "xh", title: "xh", align: "left", hide: true} , {field: "action", title: "action", align: "left", hide: true} , {field: "txmc", title: "<span></span>体系名称", width: 140, align: "left", edit: 'text'} , {field: "rztxmc", title: "<span>*</span>认证体系名称", width: 140, align: 'left', edit: 'text'} , { field: "rzrq", title: "认证日期", width: 160, align: 'left',event: 'editStartDate',data_field:'rzrq' /* templet: function (d) { return ' <input type="text" value="' + d.rzrq + '">' }*/ } , {field: "rzjg", title: "<span>*</span>认证机构", width: 140, align: 'left', edit: 'text'} , { field: "zsdqsj", title: "<span>*</span>证书到期时间", width: 160, align: 'left',event: 'editzsdqsj',data_field:'zsdqsj' /* templet: function (d) { return ' <input type="text" value="' + d.zsdqsj + '">' }*/ } , {field: "rzfgcp", title: "认证覆盖产品", width: 140, align: 'left', edit: 'text'} , { field: "jhrzsj", title: "若无,计划认证时间", width: 160, align: 'left', edit: 'select', } , {field: "ywjm", title: "原文件名", width: 140, align: 'left'} , { field: '操作', title: '操作', width: '10%', unresize: true, templet: function (res) { return '<button type="button" data-type="' + res['LAY_TABLE_INDEX'] + '" lay-event="upload"><i></i></button>&nbsp;<button type="button" lay-event="del"><i></i></button>'; } } , {field: "pc", title: "批次", align: 'left', hide: true} , {field: "cdmc", title: "cdmc", align: 'left', hide: true} , {field: "scsj", title: "scsj", align: 'left', hide: true} , {field: "ccm", title: "ccm", align: 'left', hide: true} , {field: "xg", title: "xg", align: 'left', hide: true} , {field: "fjm", title: "fjm", align: 'left', hide: true} , {field: "fjID", title: "fjID", align: 'left', hide: true} ]] , done: function (res, curr, count) { //日期控件 // 上传文件 var data = res.data; for (var i = 0; i < data.length; i++) { var elem = '#uploadFile' + i; //循环初始上传组件 var uploadInst = upload.render({ elem: elem //绑定元素 , url: $("#contextpath").val() + '/upload/uploadFile2.do' //上传接口 , field: 'files' , auto: true , accept: 'file' // ,exts: 'xls|xlsx|csv' //添加上传额外参数 , data: { sjbs: function () { var sjbs = $("#sjbs").val(); var logId = $("#logId").val(); if (sjbs !== null && sjbs.length > 0) { sjbs = sjbs; } else { sjbs = $("#sjbs").attr('name') + new Date().getTime();//设置每次新增的批次 $("#sjbs").val($("#sjbs").attr('name') + new Date().getTime());//如果没有创建时间标识,就自己新增 } mcs.setSjbs(sjbs); return sjbs; } } //文件上传前回调 , before: function (obj) { //开启加载 layer.load(2, {time: 10 * 1000, offset: '200px'}); //从表格缓存中获取table指定行数据 updateRow = tableRowTool.data; var files = this.files = obj.pushFile(); obj.preview(function (index, file, result) { updateRow['scsj'] = new Date(new Date()).format("yyyy-MM-dd hh:mm:ss"); updateRow['ywjm'] = file.name; updateRow['xg'] = 1; // updateRow['wjdx'] = (file.size/1024).toFixed(1) +'kb'; }) } //上传成功后回调 , done: function (res, index, upload) { txrzxg = true; layer.closeAll(); if (res.status === "Y") { updateRow['ccm'] = res.fileName; updateRow['sjbs'] = res.sjbs; //文件上传成功,更新表格数据 tableRowTool.update(updateRow); //文件上传成功后,去掉.layui-table-click Table选中行状态 tableRowTool.tr.prop("class", ""); layer.msg(res.msg, { icon: 1 , time: 2000 , offset: '200px' }, function () { }) } else { layer.msg(res.msg, { icon: 5 , time: 2000 , offset: '200px' }) } //删除文件队列已经上传成功的文件 return delete this.files[index]; } //上传错误回调 , error: function () { layer.closeAll(); //请求异常回调 } }); } layer.closeAll(); } })

处理方法:

//监听行工具事件 table.on('tool(tbtxrz)', function (obj) { var data = obj.data; if(obj.event === 'editStartDate'){ var field = $(this).data('field'); laydate.render({ elem: this.firstChild , show: true //直接显示 , closeStop: this , done: function (value, date) { data[field] = value; obj.update(data); } }); } else if (obj.event='editzsdqsj'){ var field = $(this).data('field'); laydate.render({ elem: this.firstChild , show: true //直接显示 , closeStop: this , done: function (value, date) { data[field] = value; obj.update(data); }}); } });

方法二:不建议使用,因为不够灵活

js代码:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8c45b42676e8bc9cc79d60bb3742ecd8.html