解决思路:<div style="width: 100px;" data-toggle="tooltip" data-placement="top" title="${displayValue}">${ displayValue.substring(0, 5) + "..." }</div>
这部分截取部分数据,超出...
{ field: "tslx", title: "投诉类型", cellStyle: formatTableUnit, formatter: function (value, row, index) { const maxChineseLength = 5; // 最大中文字符数 const maxEnglishLength = 8; // 最大英文字符数 const displayValue = value ? value : "——"; // 计算字节长度 function getByteLength(str) { let byteLength = 0; for (let i = 0; i < str.length; i++) { const char = str.charAt(i); byteLength += char.match(/[^\x00-\x80]/) ? 2 : 1; // 中文字符占用2字节,英文占1字节 } return byteLength; } // 截取显示字符串 function truncateString(str) { let byteLength = 0; let truncatedStr = ""; for (let i = 0; i < str.length; i++) { const char = str.charAt(i); const charLength = char.match(/[^\x00-\x80]/) ? 2 : 1; // 中文字符占用2字节,英文占1字节 if ( byteLength + charLength > maxChineseLength * 2 && char.match(/[^\x00-\x80]/) ) { truncatedStr += "..."; break; } else if (byteLength + charLength > maxEnglishLength) { truncatedStr += "..."; break; } byteLength += charLength; truncatedStr += char; } return truncatedStr; } // 判断是否需要截取 const truncatedValue = getByteLength(displayValue) > maxChineseLength * 2 || getByteLength(displayValue) > maxEnglishLength ? truncateString(displayValue) : displayValue; return `<div style="width: 100px;" data-toggle="tooltip" data-placement="top" title="${displayValue}">${truncatedValue}</div>`; }, },
标签:byteLength,truncatedStr,const,tooltip,char,偏移,str,displayValue,table From: https://www.cnblogs.com/tingorb/p/18546488