JavaScript/jQuery 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.

JavaScript
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • // ...
  • columns: [{
  • dataField: "Price",
  • customizeText: function(cellInfo) {
  • return cellInfo.value + "$";
  • }
  • }]
  • });
  • });

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:

JavaScript
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • // ...
  • columns: [{
  • caption: "Full Name",
  • calculateCellValue: function (rowData) {
  • return rowData.firstName + " " + rowData.lastName;
  • }
  • }]
  • });
  • });

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.

JavaScript
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • // ...
  • columns: [{
  • dataField: "Title",
  • cellTemplate: function(element, info) {
  • element.append("<div>" + info.text + "</div>")
  • .css("color", "blue");
  • }
  • }]
  • });
  • });

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.

JavaScript
CSS
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • // ...
  • onCellPrepared: function(e) {
  • if (e.rowType == "detailAdaptive") {
  • e.cellElement.addClass("adaptiveRowStyle");
  • }
  • }
  • });
  • });
  • .adaptiveRowStyle {
  • background-color: #cce6ff;
  • font-size: 12pt
  • }
See Also

Add Tooltips to Cells

The cellHintEnabled property adds a native browser tooltip to truncated cell content automatically. If you use a custom cellTemplate, you need to add the title attribute manually:

JavaScript
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • dataSource: dataSource,
  • columns: [{
  • dataField: "name",
  • caption: "Name"
  • }, {
  • dataField: "description",
  • caption: "Description",
  • cellTemplate: function(container, options) {
  • $("<div>")
  • .text(options.value)
  • .attr("title", options.value)
  • .appendTo(container);
  • }
  • }]
  • });
  • });

To add tooltips to multiple columns without modifying each cell template, use the onCellPrepared event:

JavaScript
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • dataSource: dataSource,
  • columns: ["name", "description"],
  • onCellPrepared: function(e) {
  • if (e.rowType === "data") {
  • $(e.cellElement).attr("title", e.value);
  • }
  • }
  • });
  • });

To display a styled Tooltip with custom content, initialize the Tooltip component inside cellTemplate:

JavaScript
  • $(function() {
  • $("#treeListContainer").dxTreeList({
  • dataSource: dataSource,
  • columns: [{
  • dataField: "description",
  • caption: "Description",
  • cellTemplate: function(container, options) {
  • const cellEl = $("<span>")
  • .text(options.value)
  • .appendTo(container);
  •  
  • $("<div>").dxTooltip({
  • target: cellEl,
  • showEvent: "mouseenter",
  • hideEvent: "mouseleave",
  • contentTemplate: function() {
  • return options.value;
  • }
  • }).appendTo(container);
  • }
  • }]
  • });
  • });

To add a tooltip to a header cell, use the headerCellTemplate property as described above.

You can replace "mouseenter" and "mouseleave" with other events such as "click", "dblclick", "focus", or "blur" to control when the Tooltip is displayed.