// 自定义单元格渲染方式 function customCellRenderer(params) { const value = params.value; const span = document.createElement('span'); const boldRegex = /*{2}[^*]+*{2}/g; // 匹配加粗文本 const italicRegex = /[^]+/g; // 匹配斜体文本 const boldItalicRegex = /*{2}[^*]+_*{2}/g; // 匹配加粗加斜体文本
// 处理加粗、斜体和加粗加斜体文本 if (value) { span.innerHTML = value; span.innerHTML = span.innerHTML.replace(boldItalicRegex, '$&'); span.innerHTML = span.innerHTML.replace(boldRegex, '$&'); span.innerHTML = span.innerHTML.replace(italicRegex, '$&'); }
return span; }
// 设置 gridOptions const gridOptions = { columnDefs: [ { headerName: 'Name', field: 'name', cellRenderer: customCellRenderer }, { headerName: 'Age', field: 'age' }, { headerName: 'Address', field: 'address', cellRenderer: customCellRenderer }, ], rowData: [ { name: 'John', age: 32, address: 'No. 123, 5th Avenue, New York' }, { name: 'Smith', age: 45, address: 'No. 456, 6th Street, Los Angeles' }, ], };
// 自定义 valueGetter function customValueGetter(params) { const value = params.data[params