Customize Resource Headers

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

AngularJS

HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-scheduler="{
        dataSource: schedulerData,
        currentDate: currentDate,
        resources: [ roomResource ],
        groups: [ 'roomId' ],
        resourceCellTemplate: 'header'
    }" dx-item-alias="item">
        <div data-options="dxTemplate: { name: 'header' }">
            <i style="color: blue">{{ item.text }}</i>
        </div>
    </div>
</div>
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function DemoController($scope) {
        $scope.schedulerData = [{
            text: "Meeting",
            startDate: new Date(2016, 4, 24, 9, 10),
            endDate: new Date(2016, 4, 24, 11, 20),
            roomId: 1
        }, 
        // ...
        ];
        $scope.roomResource = { 
            fieldExpr: 'roomId', 
            dataSource: [
                { id: 1, text: 'Room101', color: 'green' },
                { id: 2, text: 'Room102', color: 'red' },
                // ...
            ] 
        };
        $scope.currentDate = new Date(2016, 4, 24); 
    });
NOTE
The dx-item-alias directive specifies the variable that is used to access the item object.

Knockout

HTML
JavaScript
<div data-bind="dxScheduler: {
    dataSource: schedulerData,
    currentDate: currentDate,
    resources: [ roomResource ],
    groups: [ 'roomId' ],
    resourceCellTemplate: 'header'
}">
    <div data-options="dxTemplate: { name: 'header' }">
        <i style="color: blue" data-bind="text: text"></i>
    </div>
</div>
var viewModel= {
    schedulerData: [{
        text: "Meeting",
        startDate: new Date(2016, 4, 24, 9, 10),
        endDate: new Date(2016, 4, 24, 11, 20),
        roomId: 1
    }, 
    // ...
    ],
    roomResource: { 
        fieldExpr: 'roomId', 
        dataSource: [
            { id: 1, text: 'Room101', color: 'green' },
            { id: 2, text: 'Room102', color: 'red' },
            // ...
        ] 
    },
    currentDate: new Date(2016, 4, 24)
};

ko.applyBindings(viewModel);

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

JavaScript
var schedulerData = [{
    text: "Meeting",
    startDate: new Date(2016, 4, 24, 9, 10),
    endDate: new Date(2016, 4, 24, 11, 20),
    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

In addition, you can use a 3rd-party template engine to customize widget appearance. For more information, see the Use an Alternative Template Engine article.

See Also