You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Primereact TreeTable列提示换行问题:如何使用pre标签?

解决PrimeReact TreeTable表头Tooltip换行问题

直接用HTML换行标签<br/>或者<pre>标签结合Tooltip的escape配置就能搞定,步骤如下:

  1. 开启Tooltip的HTML解析
    在headerTooltipOptions里添加escape: false——默认PrimeReact会转义所有HTML内容,开启这个配置后才能识别HTML标签。

  2. 方法一:用<br/>实现换行
    把原有的&#10; &#13;替换成<br/>,修改后的代码:

<Column 
  columnKey="status" 
  header="Status" 
  body={status} 
  style={{ width: '150px', textAlign: "center" }} 
  headerTooltipOptions={{
    event: "both", 
    hideDelay: 1000,
    escape: false // 允许解析HTML
  }} 
  headerTooltip="Status for non-leaf nodes: count of healthy, unhealthy, warning and missing leaf nodes.<br/>Status for leaf nodes: health status."
/>
  1. 方法二:用<pre>标签保留格式
    如果需要保留文本原有的换行、空格格式,直接把内容包裹在<pre>标签里,代码示例:
<Column 
  columnKey="status" 
  header="Status" 
  body={status} 
  style={{ width: '150px', textAlign: "center" }} 
  headerTooltipOptions={{
    event: "both", 
    hideDelay: 1000,
    escape: false
  }} 
  headerTooltip="<pre>Status for non-leaf nodes: count of healthy, unhealthy, warning and missing leaf nodes.
Status for leaf nodes: health status.</pre>"
/>

补充说明:之前的&#10;和&#13;无效,是因为默认Tooltip会把这些实体转义成普通文本显示,开启escape: false后就能正常解析HTML内容了。

内容的提问来源于stack exchange,提问作者Natasha Garg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 10:53:22