layui table 导出长数值后,自动变成科学计数法了
layui table 导出长数值后,自动变成科学计数法了,网上找了一些方法,试了都不行,不过给了思路
完整代码如下,红色部分是我添加的
//表格导出 table.exportFile = function (id, data, type, name) { var that = this; data = data || table.clearCacheKey(table.cache[id]); type = type || 'csv'; var config = thisTable.config[id] || {} , textType = ({ csv: 'text/csv' , xls: 'application/vnd.ms-excel' })[type] , alink = document.createElement("a"); if (device.ie) return hint.error('IE_NOT_SUPPORT_EXPORTS'); alink.href = 'data:' + textType + ';charset=utf-8,\ufeff' + encodeURIComponent(function () { var dataTitle = [], dataMain = [], dataTotal = []; //表头和表体 layui.each(data, function (i1, item1) { var vals = []; if (typeof id === 'object') { //如果 id 参数直接为表头数据 layui.each(id, function (i, item) { i1 == 0 && dataTitle.push(item || ''); }); layui.each(table.clearCacheKey(item1), function (i2, item2) { /^[0-9]{10,}$/.test(item2) ? (item2 += '\t') : ""; vals.push('"' + (item2 || '') + '"'); }); } else { table.eachCols(id, function (i3, item3) { if (item3.field && item3.type == 'normal' && !item3.hide) { var content = item1[item3.field]; if (content === undefined || content === null) content = ''; i1 == 0 && dataTitle.push(item3.title || ''); vals.push('"' + parseTempData(item3, content, item1, 'text') + '"'); } }); } dataMain.push(vals.join(',')); }); //表合计 layui.each(that.dataTotal, function (key, value) { dataTotal.push(value); }); return dataTitle.join(',') + '\r\n' + dataMain.join('\r\n') + '\r\n' + dataTotal.join(','); }()); alink.download = (name||config.title || 'table_' + (config.index || '')) + '.' + type; document.body.appendChild(alink); alink.click(); document.body.removeChild(alink); };
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!