React TreeList - Customize Cells

Customize the Value and Text

Use the customizeText function to customize the text displayed in cells. Note that this text is not used is not used to sort, filter, and group data or calculate summaries.

App.js
  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  • import TreeList, {
  • Column
  • } from 'devextreme-react/tree-list';
  •  
  • const priceColumn_customizeText = (cellInfo) => {
  • return cellInfo.value + '$';
  • };
  •  
  • export default function App() {
  • return (
  • <TreeList ... >
  • <Column
  • dataField="Price"
  • customizeText={priceColumn_customizeText}
  • />
  • </TreeList>
  • );
  • }

To use the text displayed in cells in those data processing operations, specify the calculateCellValue function instead. It populates a column with custom values and allows you to create unbound columns - columns that are not bound to any individual data field. In the following example, this function combines full names using data from the firstName and lastName fields:

App.js
  • import React from 'react';
  •  
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import TreeList, {
  • Column
  • } from 'devextreme-react/tree-list';
  •  
  • const fullNameColumn_calculateCellValue = (rowData) => {
  • return rowData.firstName + ' ' + rowData.lastName;
  • };
  •  
  • export default function App() {
  • return (
  • <TreeList ... >
  • <Column
  • caption="Full Name"
  • calculateCellValue={fullNameColumn_calculateCellValue}
  • />
  • </TreeList>
  • );
  • }

Some features are disabled in columns with calculated values. Refer to the calculateCellValue description for a list of disabled features and the properties that enable them.

Customize the Appearance

To customize cell appearance, use a column's cellTemplate.

App.js
  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  • import TreeList, {
  • Column
  • } from 'devextreme-react/tree-list';
  •  
  • const renderCell = (data) => {
  • return <div style={{ color: 'blue' }}>{data.cell.text}</div>;
  • };
  •  
  • export default function App() {
  • return (
  • <TreeList ... >
  • <Column
  • dataField="Title"
  • cellRender={renderCell}
  • />
  • </TreeList>
  • );
  • }

While cellTemplate customizes data cells only, the onCellPrepared function can customize any cell. Unlike cellTemplate, this function does customizations after a cell is created, so you cannot use it to change the cell value. Check the rowType field of the function's argument to detect the UI element that owns the cell.

App.js
  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  • import TreeList from 'devextreme-react/tree-list';
  •  
  • const onCellPrepared = (e) => {
  • if (e.rowType == 'detailAdaptive') {
  • e.cellElement.classList.add('adaptiveRowStyle');
  • }
  • };
  •  
  • export default function App() {
  • return (
  • <TreeList ...
  • onCellPrepared={onCellPrepared}>
  • </TreeList>
  • );
  • }
See Also