React Scheduler - Customize Resource Headers

For AngularJS and Knockout apps, DevExtreme provides the dxTemplate markup component. The following code shows how to use dxTemplate to define custom templates for resource headers.

App.js
  • import React from 'react';
  •  
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { Scheduler, Resource } from 'devextreme-react/scheduler';
  •  
  • const schedulerData = [{
  • text: 'Meeting',
  • startDate: new Date("2016-04-24T09:10:00.000Z"),
  • endDate: new Date("2016-04-24T11:20:00.000Z"),
  • roomId: 1
  • },
  • // ...
  • ];
  • const rooms = [
  • { id: 1, text: 'Room101', color: 'green' },
  • { id: 2, text: 'Room102', color: 'red' },
  • // ...
  • ];
  • const currentDate = new Date(2016, 4, 24);
  • const renderResourceCell = (data) => <i style="color: blue">{data.text}</i>;
  •  
  • class App extends React.Component {
  • render() {
  • return (
  • <Scheduler
  • dataSource={schedulerData}
  • defaultCurrentDate={currentDate}
  • groups={['roomId']}
  • resourceCellRender={renderResourceCell}>
  • <Resource
  • fieldExpr="roomId"
  • dataSource={rooms} />
  • </Scheduler>
  • );
  • }
  • }
  • export default App;

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

JavaScript
  • var schedulerData = [{
  • text: "Meeting",
  • startDate: new Date("2016-04-24T09:10:00.000Z"),
  • endDate: new Date("2016-04-24T11:20:00.000Z"),
  • roomId: 1
  • },
  • // ...
  • ];
  • var roomResource = {
  • fieldExpr: 'roomId',
  • dataSource: [
  • { id: 1, text: 'Room101', color: 'green' },
  • { id: 2, text: 'Room102', color: 'red' },
  • // ...
  • ]
  • };
  •  
  • $(function () {
  • $("#schedulerContainer").dxScheduler({
  • dataSource: schedulerData,
  • currentDate: new Date(2016, 4, 24),
  • resources: [ roomResource ],
  • groups: [ 'roomId' ],
  • resourceCellTemplate: function (data, index, element) {
  • element.append("<i style='color: blue'>" + data.text + "</i>");
  • }
  • });
  • });

View Demo

See Also