JavaScript/jQuery Chat - Customize the Empty View

This tutorial illustrates how to customize the Chat's empty view. The following live example demonstrates the result:

To implement custom markup for the Chat's empty view, specify the emptyViewTemplate property. This tutorial defines an empty view container that includes a title and subtitle, as well as integrates the DevExtreme TileView component:

index.js
  • $("#chat").dxChat({
  • emptyViewTemplate: (data, element) => {
  • const $container = $("<div>").addClass('empty-view-container').css({'width': '100%', 'height': '100%'});
  •  
  • $container.append(
  • $('<div>').addClass("empty-view-titlebox").append(
  • $('<div>').addClass("empty-view-title").text("How can HR Assistant help you today?"),
  • $('<div>').addClass("empty-view-subtitle").text(data.texts.message),
  • ),
  • $('<div>').attr('id', 'tile-view-container').dxTileView({
  • // ...
  • }),
  • );
  •  
  • return $container;
  • },
  • });

To view the full source code of this tutorial, refer to the following example:

View on GitHub

This tutorial also implements the texts.message variable defined in the emptyViewTemplate parameter. The texts object includes the following variables:

VariableValue
message"There are no messages in this chat"
prompt"Write your first message"

Chat localizes these texts following your application locale. For more information about DevExtreme localization, refer to the following topic: Localization.

Customize the Chat when the Empty View is displayed

You can implement customizations outside of the empty view container and display them only when the empty view is active. For instance, to implement a custom Chat background color when the empty view is active, implement the :has() CSS pseudo-class:

index.css
  • #chat:has(.dx-chat-messagelist-empty-view) {
  • background-color: #D8E9FF;
  • }