您好,登錄后才能下訂單哦!
這篇文章主要介紹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 style='color:#c00'></span>體系名稱", width: 140, align: "left", edit: 'text'} , {field: "rztxmc", title: "<span style='color:#c00'>*</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" name="rzrq" class="layui-input layui-input-date" value="' + d.rzrq + '" id="txrzrq'+d['LAY_TABLE_INDEX'] +'">' }*/ } , {field: "rzjg", title: "<span style='color:#c00'>*</span>認證機構", width: 140, align: 'left', edit: 'text'} , { field: "zsdqsj", title: "<span style='color:#c00'>*</span>證書到期時間", width: 160, align: 'left',event: 'editzsdqsj',data_field:'zsdqsj' /* templet: function (d) { return ' <input type="text" name="zsdqsj" class="layui-input layui-input-date" value="' + d.zsdqsj + '" id="test2">' }*/ } , {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" class="layui-btn layui-btn-xs" data-type="' + res['LAY_TABLE_INDEX'] + '" id="uploadFile' + res['LAY_TABLE_INDEX'] + '" lay-event="upload"><i class="layui-icon layui-icon-upload-drag"></i></button> <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></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代碼:
var layer = layui.layer, form = layui.form, table = layui.table; var $ = layui.$; /*select gysmc,zyzw ,xm ,sjhm ,bgshm ,emilyx , zgsrgzwsj ,zggsgl ,cast(gysxxid as int) as gysxxid, pc, gysryxxMdataID as ID,sjbs from gysryxxMdata*/ var tableInit = table.render({ elem: '#tbgysplay' , method: 'post' , data: jsonData , height: "auto" , id: "tbgysplay" , text: {none: '暫無相關數據'} , toolbar: "#toolbarplan" , cols: [[ {type: "checkbox", fixed: "left", width: 50} , { field: "number", title: "序號", width: '10%', align: "left", templet: function (data) { return data.LAY_INDEX } } , {field: "ID", title: "ID", align: "left", hide: true} , {field: "action", title: "action", align: "left", hide: true} , {field: "sjbs", title: "sjbs", align: "left", hide: true} , {field: "供應商名稱", title: "供應商名稱", width: '15%', align: "left"} , {field: "主要產品類型", title: "主要產品類型", width: '15%', align: 'left'} , {field: "所在省份", title: "所在省份", width: '15%', align: 'left'} , { field: "PSA計劃時間", title: "PSA計劃時間", width: '20%', align: 'left', templet:function (d) { return ' <input type="text" class="layui-input layui-input-date" value="'+d.PSA計劃時間+'" id="test1">' } } , {field: "PSA計劃負責人", title: "PSA計劃負責人", align: 'left',edit:'text'} ]] , done: function (res) {//當數據渲染完后,執行的回調 //日期控件 $(".layui-input-date").each(function (i) { layui.laydate.render({ elem: this, format: "yyyy-MM-dd", done: function (value, date) { if (res && res.data[i]) { $.extend(res.data[i], {'PSA計劃時間': value}) } } }); }); layer.closeAll(); } });
以上是“layui中table表格上如何添加日期控件”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。