React TileView - Customize Tile Appearance

For a minor customization of tiles, you can define specific fields in item data objects. For example, the following code generates three tiles: the first is disabled, the second is not customized, the third is hidden.

  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { TileView } from 'devextreme-react/tile-view';
  •  
  • const dataSource = [
  • { text: 'Alabama', disabled: true },
  • { text: 'Alaska' },
  • { text: 'Arizona', visible: false }
  • ];
  •  
  • class App extends React.Component {
  • render() {
  • return (
  • <TileView dataSource={dataSource}/>
  • );
  • }
  • }
  •  
  • export default App;

If you need a more flexible solution, define an itemTemplate. In Angular and Vue, you can declare it in the markup. In React, you can use a rendering function (shown in the code below) or component:

App.js
styles.css
  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { TileView } from 'devextreme-react/tile-view';
  •  
  • const tileViewData = [
  • { name: "Alabama", capital: "Montgomery" },
  • { name: "Alaska", capital: "Juneau" },
  • { name: "Arizona", capital: "Phoenix" },
  • // ...
  • ];
  •  
  • const renderTileItem = (itemData) => {
  • return (
  • <div>
  • <p style={{fontSize: "larger"}}>{itemData.name}</p>
  • <p><i>{itemData.capital}</i></p>
  • </div>
  • );
  • }
  •  
  • class App extends React.Component {
  • render() {
  • return (
  • <TileView
  • items={tileViewData}
  • itemRender={renderTileItem}
  • />
  • );
  • }
  • }
  • export default App;
  • .tile {
  • border-radius: .5em;
  • text-align: center;
  • color: white;
  • background: gray;
  • }

If you use jQuery alone, use DOM manipulation methods to combine the HTML markup for tiles. To apply this markup, use the itemTemplate callback function as shown in the following code:

You can also customize individual tiles. In Angular, Vue, and React, declare them using the dxItem component. When using jQuery, you can declare the tiles as scripts and reference them in the template property or assign a customization function straight to this property.

  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { TileView, Item } from 'devextreme-react/tile-view';
  •  
  • class App extends React.Component {
  • render() {
  • return (
  • <TileView>
  • <Item>
  • <span>User</span>
  • </Item>
  • <Item>
  • <span>Comment</span>
  • </Item>
  • </TileView>
  • );
  • }
  • }
  •  
  • export default App;

In addition, you can use a 3rd-party template engine to customize UI component appearance. For more information, see the 3rd-Party Template Engines article.

Built-In Template Engine Demo 3rd-Party Template Engine Demo

See Also