How to display text containing html tags in Kendo react treelist column?

1 Answer 12 Views
TreeList
Satbir
Top achievements
Rank 1
Satbir asked on 15 Mar 2024, 04:40 PM

Hello,

I am trying to display text containing html tags (rich text) in the treelist columns. Can you suggest how to do that? Currently it is showing as a string.

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 19 Mar 2024, 03:45 PM

Hi, Satbir,

In order to render html content in the cells of the TreeList you will need to create a custom cell and allow the html rendering inside it explicitly. For example, you can use the `dangerouslySetInnerHTML` attribute of a div to achieve that:

const MyCell = (props: TreeListCellProps) => {
  const { dataItem } = props;
  const field = props.field || '';
  const cellData = dataItem[field];
  var wrapper = document.createElement('div');
  wrapper.innerHTML = cellData;
  return (
    <td>
      <div dangerouslySetInnerHTML={{ __html: cellData }} />
    </td>
  );
};

You can test the suggestion above in the following sample (refer the third column):

I hope this will prove helpful but let me know in case I can assist you any further on this matter.

Regards,
Vessy
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources!

Tags
TreeList
Asked by
Satbir
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or